#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*/ readBuffer;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SYS_close;
int /*<<< orphan*/ SYS_open;
int /*<<< orphan*/ SYS_read;
scalar_t__ findAndPrint(char *, int const);
int syscall(int /*<<< orphan*/, ...);
void printID(const int ID, char *path) {
  char readBuffer[1048576];
  int fd = syscall(SYS_open, path, O_RDONLY);
  syscall(SYS_read, fd, readBuffer, sizeof(readBuffer));
  char *poof = readBuffer;
  while (*poof && poof) {
    int i = 0;
    char temp_line[1000];
    while (*poof && *poof != '\n') {
      temp_line[i] = *poof;
      poof++;
      i++;
    }
    temp_line[i] = '\n';
    temp_line[i + 1] = 0;
    if (findAndPrint(temp_line, ID))
      break;
    poof++;
  }
  syscall(SYS_close, fd);
}


x86 assembly (clang, -O0):
<printID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    0x2ea2(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1030 <syscall@plt>
mov    %eax,-0x100014(%rbp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    -0x100014(%rbp),%esi
lea    -0x100010(%rbp),%rdx
mov    $0x100000,%ecx
mov    $0x0,%al
call   1030 <syscall@plt>
lea    -0x100010(%rbp),%rax
mov    %rax,-0x100020(%rbp)
mov    -0x100020(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x100411(%rbp)
je     11b1 <printID+0x91>
cmpq   $0x0,-0x100020(%rbp)
setne  %al
mov    %al,-0x100411(%rbp)
mov    -0x100411(%rbp),%al
test   $0x1,%al
jne    11c4 <printID+0xa4>
jmp    12a6 <printID+0x186>
movl   $0x0,-0x100024(%rbp)
mov    -0x100020(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x100412(%rbp)
je     11ff <printID+0xdf>
mov    -0x100020(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x100412(%rbp)
mov    -0x100412(%rbp),%al
test   $0x1,%al
jne    1212 <printID+0xf2>
jmp    124f <printID+0x12f>
mov    -0x100020(%rbp),%rax
mov    (%rax),%cl
movslq -0x100024(%rbp),%rax
mov    %cl,-0x100410(%rbp,%rax,1)
mov    -0x100020(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x100020(%rbp)
mov    -0x100024(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x100024(%rbp)
jmp    11ce <printID+0xae>
movslq -0x100024(%rbp),%rax
movb   $0xa,-0x100410(%rbp,%rax,1)
0a
mov    -0x100024(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x100410(%rbp,%rax,1)
lea    -0x100410(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1040 <findAndPrint@plt>
cmp    $0x0,%rax
je     128f <printID+0x16f>
jmp    12a6 <printID+0x186>
mov    -0x100020(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x100020(%rbp)
jmp    1185 <printID+0x65>
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
mov    -0x100014(%rbp),%esi
mov    $0x0,%al
call   1030 <syscall@plt>
add    $0x100420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printID>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1003f0,%rsp
mov    %edi,%r12d
lea    0x3f0(%rsp),%rbx
mov    0x2e87(%rip),%rax
mov    (%rax),%edi
mov    0x2e9e(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
call   1030 <syscall@plt>
mov    %eax,%r14d
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    $0x100000,%ecx
mov    %r14d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <syscall@plt>
mov    %rsp,%r15
jmp    11a4 <printID+0x84>
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%eax
movb   $0xa,(%rsp,%rax,1)
lea    0x1(%rbp),%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %r12d,%esi
call   1040 <findAndPrint@plt>
add    %rbp,%rbx
add    $0x1,%rbx
test   %rax,%rax
jne    11c6 <printID+0xa6>
mov    (%rbx),%al
test   %al,%al
je     11c6 <printID+0xa6>
xor    %ebp,%ebp
test   %al,%al
je     1180 <printID+0x60>
cmp    $0xa,%al
je     1180 <printID+0x60>
mov    %al,(%rsp,%rbp,1)
movzbl 0x1(%rbx,%rbp,1),%eax
add    $0x1,%rbp
test   %al,%al
jne    11b0 <printID+0x90>
jmp    1180 <printID+0x60>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <syscall@plt>
add    $0x1003f0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SYS_open = global i32 0
@O_RDONLY = global i32 0
@SYS_read = global i32 0
@SYS_close = global i32 0
define void @printID(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [1048576 x i8]
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [1000 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = load i32, i32* @SYS_open
%11 = load i8*, i8** %4
%12 = load i32, i32* @O_RDONLY
%13 = call i32 (i32, ...) @syscall(i32 %10, i8* %11, i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* @SYS_read
%15 = load i32, i32* %6
%16 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %5, i64 0, i64 0
%17 = call i32 (i32, ...) @syscall(i32 %14, i32 %15, i8* %16, i64 1048576)
%18 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %5, i64 0, i64 0
store i8* %18, i8** %7
br label %19
19: ; preds = %65, %2
%20 = load i8*, i8** %7
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br label %27
27: ; preds = %24, %19
%28 = phi i1 [ false, %19 ], [ %26, %24 ]
br i1 %28, label %29, label %68
29: ; preds = %27
store i32 0, i32* %8
br label %30
30: ; preds = %42, %29
%31 = load i8*, i8** %7
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %30
%36 = load i8*, i8** %7
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 10
br label %40
40: ; preds = %35, %30
%41 = phi i1 [ false, %30 ], [ %39, %35 ]
br i1 %41, label %42, label %52
42: ; preds = %40
%43 = load i8*, i8** %7
%44 = load i8, i8* %43
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 %46
store i8 %44, i8* %47
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %7
%50 = load i32, i32* %8
%51 = add nsw i32 %50, 1
store i32 %51, i32* %8
br label %30
52: ; preds = %40
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 %54
store i8 10, i8* %55
%56 = load i32, i32* %8
%57 = add nsw i32 %56, 1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 %58
store i8 0, i8* %59
%60 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%61 = load i32, i32* %3
%62 = call i64 @findAndPrint(i8* %60, i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %52
br label %68
65: ; preds = %52
%66 = load i8*, i8** %7
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %7
br label %19
68: ; preds = %64, %27
%69 = load i32, i32* @SYS_close
%70 = load i32, i32* %6
%71 = call i32 (i32, ...) @syscall(i32 %69, i32 %70)
ret void
}

LLVM IR (-O2):
@SYS_open = global i32 0
@O_RDONLY = global i32 0
@SYS_read = global i32 0
@SYS_close = global i32 0
define void @printID(i32 %0, i8* %1) {
%3 = alloca [1048576 x i8]
%4 = alloca [1000 x i8]
%5 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @SYS_open
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 (i32, ...) @syscall(i32 %6, i8* %1, i32 %7)
%9 = load i32, i32* @SYS_read
%10 = call i32 (i32, ...) @syscall(i32 %9, i32 %8, i8* %5, i64 1048576)
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
br label %12
12: ; preds = %26, %2
%13 = phi i8* [ %5, %2 ], [ %34, %26 ]
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %35, label %16
16: ; preds = %12
br label %17
17: ; preds = %21, %16
%18 = phi i8 [ %25, %21 ], [ %14, %16 ]
%19 = phi i64 [ %24, %21 ], [ 0, %16 ]
%20 = phi i8* [ %23, %21 ], [ %13, %16 ]
switch i8 %18, label %21 [
i8 0, label %26
i8 10, label %26
]
21: ; preds = %17
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %19
store i8 %18, i8* %22
%23 = getelementptr inbounds i8, i8* %20, i64 1
%24 = add nuw i64 %19, 1
%25 = load i8, i8* %23
br label %17
26: ; preds = %17, %17
%27 = and i64 %19, 4294967295
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %27
store i8 10, i8* %28
%29 = add i64 %19, 1
%30 = and i64 %29, 4294967295
%31 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i64 @findAndPrint(i8* %11, i32 %0)
%33 = icmp eq i64 %32, 0
%34 = getelementptr inbounds i8, i8* %20, i64 1
br i1 %33, label %12, label %35
35: ; preds = %26, %12
%36 = load i32, i32* @SYS_close
%37 = call i32 (i32, ...) @syscall(i32 %36, i32 %8)
ret void
}