#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 /*<<< orphan*/ file_load(char *, char **, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *filename = NULL;
  char *image = NULL;
  char *ptr = NULL;
  FILE *out = NULL;
  int image_size = 0;
  int size = 0;
  int offset = 0;
  int i = 0;
  if (argc != 2) {
    fprintf(stderr, "syntax:: check_null file_name\n");
    return 1;
  }
  filename = argv[1];
  if (!file_load(filename, &image, &image_size)) {
    printf("execve:: error loading file\n");
    return -1;
  }
  for (i = 0; i < image_size; ++i) {
    if (image[i] == 0x0) {
      printf("null found at [%d]\n", i);
    } else {
      printf("%x found at [%d]\n", image[i], i);
    }
  }
}


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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ad <main+0x7d>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    125b <main+0x12b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1050 <file_load@plt>
cmp    $0x0,%eax
jne    11ed <main+0xbd>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125b <main+0x12b>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    125b <main+0x12b>
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    122b <main+0xfb>
mov    -0x40(%rbp),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1248 <main+0x118>
mov    -0x20(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
mov    -0x40(%rbp),%edx
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    124d <main+0x11d>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    11f4 <main+0xc4>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
movl   $0x0,0x4(%rsp)
cmp    $0x2,%edi
jne    11c5 <main+0x85>
mov    0x8(%rsi),%rdi
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1060 <file_load@plt>
test   %eax,%eax
je     11e5 <main+0xa5>
cmpl   $0x0,0x4(%rsp)
jle    11e1 <main+0xa1>
lea    0xe9b(%rip),%r14
lea    0xea8(%rip),%r15
xor    %ebx,%ebx
jmp    11aa <main+0x6a>
nop
mov    %r15,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
movslq 0x4(%rsp),%rax
cmp    %rax,%rbx
jge    11e1 <main+0xa1>
mov    0x8(%rsp),%rax
movsbl (%rax,%rbx,1),%esi
test   %esi,%esi
jne    1190 <main+0x50>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    119c <main+0x5c>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11f6 <main+0xb6>
xor    %eax,%eax
jmp    11f6 <main+0xb6>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"syntax:: check_null file_name\0A\00"
@.str.1 = [29 x i8] c"execve:: error loading file\0A\00"
@.str.2 = [20 x i8] c"null found at [%d]\0A\00"
@.str.3 = [18 x i8] c"%x found at [%d]\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 i8*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i8* null, i8** %7
store i8* null, i8** %8
store i32* null, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %57
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @file_load(i8* %23, i8** %7, i32* %10)
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %19
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %57
28: ; preds = %19
store i32 0, i32* %13
br label %29
29: ; preds = %54, %28
%30 = load i32, i32* %13
%31 = load i32, i32* %10
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %57
33: ; preds = %29
%34 = load i8*, i8** %7
%35 = load i32, i32* %13
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %33
%42 = load i32, i32* %13
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %42)
br label %53
44: ; preds = %33
%45 = load i8*, i8** %7
%46 = load i32, i32* %13
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = load i32, i32* %13
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 %51)
br label %53
53: ; preds = %44, %41
br label %54
54: ; preds = %53
%55 = load i32, i32* %13
%56 = add nsw i32 %55, 1
store i32 %56, i32* %13
br label %29
57: ; preds = %16, %26, %29
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"syntax:: check_null file_name\0A\00"
@.str.2 = [20 x i8] c"null found at [%d]\0A\00"
@.str.3 = [18 x i8] c"%x found at [%d]\0A\00"
@str = [28 x i8] c"execve:: error loading file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = icmp eq i32 %0, 2
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %39
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @file_load(i8* %13, i8** %3, i32* %4)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %21, label %39
19: ; preds = %11
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %39
21: ; preds = %16, %34
%22 = phi i64 [ %35, %34 ], [ 0, %16 ]
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 %22
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = trunc i64 %22 to i32
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %34
30: ; preds = %21
%31 = sext i8 %25 to i32
%32 = trunc i64 %22 to i32
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %31, i32 %32)
br label %34
34: ; preds = %27, %30
%35 = add nuw nsw i64 %22, 1
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %21, label %39
39: ; preds = %34, %16, %19, %8
%40 = phi i32 [ 1, %8 ], [ -1, %19 ], [ 0, %16 ], [ 0, %34 ]
ret i32 %40
}