#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int main(int argc, char *argv[]) {
  char buffer[20] = {0};
  char *p;
  int fd;
  int size;
  if (argc != 2) {
    printf("Usage: %s <file>\n", argv[0]);
    exit(-1);
  }
  if ((fd = open(argv[1], O_RDONLY)) == -1) {
    do {
      perror("open");
      exit(-1);
    } while (0);
    ;
  }
  if (read(fd, buffer, 20) != 20) {
    do {
      perror("read");
      exit(-1);
    } while (0);
    ;
  }
  p = buffer;
  size = *(unsigned int *)p;
  p += sizeof(unsigned int);
  if (size > 0) {
    printf("ok\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
je     11af <main+0x4f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    11ec <main+0x8c>
jmp    11d6 <main+0x76>
lea    0xe35(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x3c(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x14,%edx
call   1050 <read@plt>
cmp    $0x14,%eax
je     1221 <main+0xc1>
jmp    120b <main+0xab>
lea    0xe05(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    -0x38(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x40(%rbp)
jle    1256 <main+0xf6>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
cmp    $0x2,%edi
jne    11bc <main+0x5c>
mov    0x8(%rsi),%rdi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11d7 <main+0x77>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x14,%edx
call   1050 <read@plt>
cmp    $0x14,%eax
jne    11e0 <main+0x80>
cmpl   $0x0,(%rsp)
jle    11b5 <main+0x55>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    (%rsi),%rsi
lea    0xe3a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
lea    0xe34(%rip),%rdi
jmp    11e7 <main+0x87>
lea    0xe30(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [5 x i8] c"read\00"
@.str.3 = [4 x i8] c"ok\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [20 x i8]* %6 to i8*
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23)
store i32 %24, i32* %8
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %31
26: ; preds = %19
br label %27
27: ; preds = %26
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; No predecessors!
br label %31
31: ; preds = %30, %19
%32 = load i32, i32* %8
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 20)
%35 = icmp ne i32 %34, 20
br i1 %35, label %36, label %41
36: ; preds = %31
br label %37
37: ; preds = %36
%38 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; No predecessors!
br label %41
41: ; preds = %40, %31
%42 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
store i8* %42, i8** %7
%43 = load i8*, i8** %7
%44 = bitcast i8* %43 to i32*
%45 = load i32, i32* %44
store i32 %45, i32* %9
%46 = load i8*, i8** %7
%47 = getelementptr inbounds i8, i8* %46, i64 4
store i8* %47, i8** %7
%48 = load i32, i32* %9
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %41
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %50, %41
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [5 x i8] c"read\00"
@str = [3 x i8] c"ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %10
%20 = call i32 @read(i32 %14, i8* %4, i32 20)
%21 = icmp eq i32 %20, 20
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %19
%26 = bitcast [20 x i8]* %3 to i32*
%27 = load i32, i32* %26
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
ret i32 0
}