#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 fun(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, 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, *buffer1;
  int count = 0;
  int fd;
  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 ((buffer = malloc(4)) == NULL) {
    do {
      perror("malloc");
      exit(-1);
    } while (0);
    ;
  }
  if ((buffer1 = malloc(4)) == NULL) {
    do {
      perror("malloc");
      exit(-1);
    } while (0);
    ;
  }
  if (read(fd, buffer, 4) != 4) {
    do {
      perror("read");
      exit(-1);
    } while (0);
    ;
  }
  memcpy(buffer1, buffer, 4);
  count = fun(buffer1);
  if (count == 4) {
    printf("ok\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11c6 <main+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    1203 <main+0x83>
jmp    11ed <main+0x6d>
lea    0xe1e(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1236 <main+0xb6>
jmp    1220 <main+0xa0>
lea    0xdf0(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1269 <main+0xe9>
jmp    1253 <main+0xd3>
lea    0xdbd(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1050 <read@plt>
cmp    $0x4,%eax
je     129e <main+0x11e>
jmp    1288 <main+0x108>
lea    0xd8f(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1060 <memcpy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fun@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jne    12d4 <main+0x154>
lea    0xd56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    122d <main+0x9d>
mov    0x8(%rsi),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1248 <main+0xb8>
mov    %eax,%r14d
mov    $0x4,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1224 <main+0x94>
mov    %rax,%rbx
mov    $0x4,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1224 <main+0x94>
mov    %rax,%rbp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1060 <read@plt>
cmp    $0x4,%eax
jne    1251 <main+0xc1>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
mov    %rbp,%rdi
call   1040 <fun@plt>
cmp    $0x4,%eax
jne    121d <main+0x8d>
lea    0xe0b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdec(%rip),%rdi
jmp    1258 <main+0xc8>
mov    (%rsi),%rsi
lea    0xdc9(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
lea    0xdc3(%rip),%rdi
jmp    1258 <main+0xc8>
lea    0xdc6(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <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 = [7 x i8] c"malloc\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [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 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
store i32 0, i32* %8
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* %21, i32 %22)
store i32 %23, i32* %9
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %30
25: ; preds = %18
br label %26
26: ; preds = %25
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; No predecessors!
br label %30
30: ; preds = %29, %18
%31 = call i8* @malloc(i32 4)
store i8* %31, i8** %6
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %38
33: ; preds = %30
br label %34
34: ; preds = %33
%35 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%36 = call i32 @exit(i32 -1)
unreachable
37: ; No predecessors!
br label %38
38: ; preds = %37, %30
%39 = call i8* @malloc(i32 4)
store i8* %39, i8** %7
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %46
41: ; preds = %38
br label %42
42: ; preds = %41
%43 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 -1)
unreachable
45: ; No predecessors!
br label %46
46: ; preds = %45, %38
%47 = load i32, i32* %9
%48 = load i8*, i8** %6
%49 = call i32 @read(i32 %47, i8* %48, i32 4)
%50 = icmp ne i32 %49, 4
br i1 %50, label %51, label %56
51: ; preds = %46
br label %52
52: ; preds = %51
%53 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 -1)
unreachable
55: ; No predecessors!
br label %56
56: ; preds = %55, %46
%57 = load i8*, i8** %7
%58 = load i8*, i8** %6
%59 = call i32 @memcpy(i8* %57, i8* %58, i32 4)
%60 = load i8*, i8** %7
%61 = call i32 @fun(i8* %60)
store i32 %61, i32* %8
%62 = load i32, i32* %8
%63 = icmp eq i32 %62, 4
br i1 %63, label %64, label %66
64: ; preds = %56
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
br label %66
66: ; preds = %64, %56
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 = [7 x i8] c"malloc\00"
@.str.3 = [5 x i8] c"read\00"
@str = [3 x i8] c"ok\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 @exit(i32 -1)
unreachable
17: ; preds = %8
%18 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 @exit(i32 -1)
unreachable
23: ; preds = %17
%24 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @exit(i32 -1)
unreachable
29: ; preds = %23
%30 = tail call i32 @read(i32 %12, i8* %18, i32 4)
%31 = icmp eq i32 %30, 4
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%34 = tail call i32 @exit(i32 -1)
unreachable
35: ; preds = %29
%36 = tail call i32 @memcpy(i8* %24, i8* %18, i32 4)
%37 = tail call i32 @fun(i8* %24)
%38 = icmp eq i32 %37, 4
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
ret i32 0
}