#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*/ close(int);
int /*<<< orphan*/ fatal(char *);
int getuid();
int open(char *, int /*<<< orphan*/);
int print_notes(int, int, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  int userid, printing = 1, fd;
  char searchstring[100];
  if (argc > 1)
    strcpy(searchstring, argv[1]);
  else
    searchstring[0] = 0;
  userid = getuid();
  fd = open("bin/notes", O_RDONLY);
  if (fd == -1)
    fatal("in main() while opening file for reading");
  while (printing)
    printing = print_notes(fd, userid, searchstring);
  printf("-------[ end of note data ]-------\n");
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11b0 <main+0x40>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
jmp    11b4 <main+0x44>
movb   $0x0,-0x80(%rbp)
mov    $0x0,%al
call   1050 <getuid@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
lea    0xe32(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ec <main+0x7c>
lea    0xe23(%rip),%rdi
call   1090 <fatal@plt>
jmp    11f1 <main+0x81>
cmpl   $0x0,-0x18(%rbp)
je     1212 <main+0xa2>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
lea    -0x80(%rbp),%rdx
call   1030 <print_notes@plt>
mov    %eax,-0x18(%rbp)
jmp    11f1 <main+0x81>
lea    0xe1a(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
cmp    $0x2,%edi
jl     118b <main+0x1b>
mov    0x8(%rsi),%rsi
mov    %rsp,%rdi
call   1040 <strcpy@plt>
jmp    118f <main+0x1f>
movb   $0x0,(%rsp)
xor    %eax,%eax
call   1060 <getuid@plt>
mov    %eax,%ebx
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xe58(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11c0 <main+0x50>
lea    0xe4f(%rip),%rdi
call   1090 <fatal@plt>
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %ebp,%edi
mov    %ebx,%esi
mov    %r14,%rdx
call   1030 <print_notes@plt>
test   %eax,%eax
jne    11d0 <main+0x60>
lea    0xe4c(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"bin/notes\00"
@O_RDONLY = global i32 0
@.str.1 = [41 x i8] c"in main() while opening file for reading\00"
@.str.2 = [36 x i8] c"-------[ end of note data ]-------\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strcpy(i8* %13, i8* %16)
br label %20
18: ; preds = %2
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
store i8 0, i8* %19
br label %20
20: ; preds = %18, %12
%21 = call i32 (...) @getuid()
store i32 %21, i32* %6
%22 = load i32, i32* @O_RDONLY
%23 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @fatal(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %20
br label %29
29: ; preds = %32, %28
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i32, i32* %8
%34 = load i32, i32* %6
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i64 0, i64 0
%36 = call i32 @print_notes(i32 %33, i32 %34, i8* %35)
store i32 %36, i32* %7
br label %29
37: ; preds = %29
%38 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* %8
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [10 x i8] c"bin/notes\00"
@O_RDONLY = global i32 0
@.str.1 = [41 x i8] c"in main() while opening file for reading\00"
@str = [35 x i8] c"-------[ end of note data ]-------\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = call i32 @strcpy(i8* %4, i8* %8)
br label %11
10: ; preds = %2
store i8 0, i8* %4
br label %11
11: ; preds = %10, %6
%12 = call i32 (...) @getuid()
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @fatal(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %11
br label %19
19: ; preds = %18, %19
%20 = call i32 @print_notes(i32 %14, i32 %12, i8* %4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %19
22: ; preds = %19
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%24 = call i32 @close(i32 %14)
ret i32 0
}