#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, int *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  printf("Look at the stuff in /proc\n");
  FILE *f = fopen("/proc/self/status", "r");
  printf("fopen() returned %p\n", f);
  if (f > 0) {
    int x;
    for (x = 0; x < 10; x++) {
      char name[1024];
      int num;
      int matchNum = fscanf(f, "%s %d", name, &num);
      printf("fscanf() returned %d : %s : %d\n", matchNum, name, num);
    }
    fclose(f);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
jbe    1208 <main+0xc8>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
jge    11ff <main+0xbf>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rdx
lea    0xe87(%rip),%rsi
lea    -0x424(%rbp),%rcx
call   1050 <fscanf@plt>
mov    %eax,-0x428(%rbp)
mov    -0x428(%rbp),%esi
lea    -0x420(%rbp),%rdx
mov    -0x424(%rbp),%ecx
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a2 <main+0x62>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x410,%rsp
lea    0xee8(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8d(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe8b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
test   %rbx,%rbx
je     1324 <main+0x1d4>
lea    0xe86(%rip),%r15
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r12
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%ecx
lea    0xe66(%rip),%r13
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%ecx
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%ecx
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%ecx
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%ecx
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%ecx
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%ecx
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%ecx
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%ecx
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1060 <fscanf@plt>
mov    0xc(%rsp),%ecx
mov    %r13,%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Look at the stuff in /proc\0A\00"
@.str.1 = [18 x i8] c"/proc/self/status\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"fopen() returned %p\0A\00"
@.str.4 = [6 x i8] c"%s %d\00"
@.str.5 = [32 x i8] c"fscanf() returned %d : %s : %d\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 [1024 x i8]
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32* %13)
%15 = load i32*, i32** %6
%16 = icmp ugt i32* %15, null
br i1 %16, label %17, label %35
17: ; preds = %2
store i32 0, i32* %7
br label %18
18: ; preds = %29, %17
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 10
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i32*, i32** %6
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%24 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %23, i32* %9)
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = load i32, i32* %9
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %25, i8* %26, i32 %27)
br label %29
29: ; preds = %21
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %18
32: ; preds = %18
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %32, %2
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"/proc/self/status\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [21 x i8] c"fopen() returned %p\0A\00"
@.str.4 = [6 x i8] c"%s %d\00"
@.str.5 = [32 x i8] c"fscanf() returned %d : %s : %d\0A\00"
@str = [27 x i8] c"Look at the stuff in /proc\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%8 = icmp eq i32* %6, null
br i1 %8, label %43, label %9
9: ; preds = %2
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = bitcast i32* %4 to i8*
%12 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %4)
%13 = load i32, i32* %4
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %12, i8* %10, i32 %13)
%15 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %4)
%16 = load i32, i32* %4
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %15, i8* %10, i32 %16)
%18 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %4)
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %18, i8* %10, i32 %19)
%21 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %4)
%22 = load i32, i32* %4
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %21, i8* %10, i32 %22)
%24 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %4)
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %24, i8* %10, i32 %25)
%27 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %4)
%28 = load i32, i32* %4
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %27, i8* %10, i32 %28)
%30 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %4)
%31 = load i32, i32* %4
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %30, i8* %10, i32 %31)
%33 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %4)
%34 = load i32, i32* %4
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %33, i8* %10, i32 %34)
%36 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %4)
%37 = load i32, i32* %4
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %36, i8* %10, i32 %37)
%39 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %10, i32* %4)
%40 = load i32, i32* %4
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %39, i8* %10, i32 %40)
%42 = call i32 @fclose(i32* %6)
br label %43
43: ; preds = %9, %2
ret i32 0
}