#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int checkbin(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ platform_init();
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int ac, char **av) {
  char *file;
  FILE *f;
  int r;
  platform_init();
  if (ac != 2) {
    fprintf(stderr, "checkbin: wrong number of arguments\n");
    fprintf(stderr, "Usage: checkbin file\n");
    return 2;
  }
  file = av[1];
  if (strcmp(file, "-") == 0) {
    f = stdin;
  } else {
    f = fopen(file, "rb");
    if (!f) {
      fprintf(stderr, "checkbin: %s: %s\n", file, strerror(errno));
      return 2;
    }
  }
  r = checkbin(f);
  if (strcmp(file, "-") == 0) {
  } else {
    fclose(f);
  }
  return r;
}


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)
mov    $0x0,%al
call   1030 <platform_init@plt>
cmpl   $0x2,-0x8(%rbp)
je     11d1 <main+0x61>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe67(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12ae <main+0x13e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    120a <main+0x9a>
mov    0x2dea(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1274 <main+0x104>
mov    -0x18(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    126f <main+0xff>
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    12ae <main+0x13e>
jmp    1274 <main+0x104>
mov    -0x20(%rbp),%rdi
call   1080 <checkbin@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdb0(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    129f <main+0x12f>
jmp    12a8 <main+0x138>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <platform_init@plt>
cmp    $0x2,%ebp
jne    11e3 <main+0x73>
mov    0x8(%rbx),%r14
lea    0xeab(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1211 <main+0xa1>
lea    0xe99(%rip),%rsi
mov    %r14,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    121b <main+0xab>
mov    0x2e1d(%rip),%rax
mov    (%rax),%ebx
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe6e(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    120a <main+0x9a>
mov    0x2dee(%rip),%rbx
mov    (%rbx),%edi
lea    0xe0d(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe22(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%ebp
jmp    1241 <main+0xd1>
mov    0x2dd0(%rip),%rax
mov    (%rax),%rbx
mov    %rbx,%rdi
call   1080 <checkbin@plt>
mov    %eax,%ebp
lea    0xe0f(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1241 <main+0xd1>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"checkbin: wrong number of arguments\0A\00"
@.str.1 = [22 x i8] c"Usage: checkbin file\0A\00"
@.str.2 = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [18 x i8] c"checkbin: %s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @platform_init()
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %50
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %17
%25 = load i32*, i32** @stdin
store i32* %25, i32** %7
br label %38
26: ; preds = %17
%27 = load i8*, i8** %6
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %28, i32** %7
%29 = load i32*, i32** %7
%30 = icmp ne i32* %29, null
br i1 %30, label %37, label %31
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %6
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %33, i8* %35)
store i32 2, i32* %3
br label %50
37: ; preds = %26
br label %38
38: ; preds = %37, %24
%39 = load i32*, i32** %7
%40 = call i32 @checkbin(i32* %39)
store i32 %40, i32* %8
%41 = load i8*, i8** %6
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
br label %48
45: ; preds = %38
%46 = load i32*, i32** %7
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %45, %44
%49 = load i32, i32* %8
store i32 %49, i32* %3
br label %50
50: ; preds = %48, %31, %12
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"checkbin: wrong number of arguments\0A\00"
@.str.1 = [22 x i8] c"Usage: checkbin file\0A\00"
@.str.2 = [2 x i8] c"-\00"
@stdin = global i32* null
@.str.3 = [3 x i8] c"rb\00"
@.str.4 = [18 x i8] c"checkbin: %s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @platform_init()
%4 = icmp eq i32 %0, 2
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %32
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32*, i32** @stdin
br label %25
17: ; preds = %10
%18 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = tail call i8* @strerror(i32 %22)
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %12, i8* %23)
br label %32
25: ; preds = %17, %15
%26 = phi i32* [ %16, %15 ], [ %18, %17 ]
%27 = tail call i32 @checkbin(i32* %26)
%28 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = tail call i32 @fclose(i32* %26)
br label %32
32: ; preds = %30, %25, %20, %5
%33 = phi i32 [ 2, %5 ], [ 2, %20 ], [ %27, %25 ], [ %27, %30 ]
ret i32 %33
}