#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int load_contacts(char names[10][20], char addresses[10][200],
                  char phoneNumbers[10][10]) {
  int numItems = 0;
  FILE *infile = fopen("contacts.dat", "r");
  if (infile == NULL) {
    return 0;
  }
  fscanf(infile, "%d", &numItems);
  if (numItems >= 10) {
    numItems = 10;
  }
  int i;
  for (i = 0; i < numItems; i++) {
    fgets(names[i], 20, infile);
  }
  for (i = 0; i < numItems; i++) {
    fgets(addresses[i], 200, infile);
  }
  for (i = 0; i < numItems; i++) {
    fgets(phoneNumbers[i], 10, infile);
  }
  fclose(infile);
  return numItems;
}


x86 assembly (clang, -O0):
<load_contacts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xe9e(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1189 <load_contacts+0x49>
movl   $0x0,-0x4(%rbp)
jmp    127a <load_contacts+0x13a>
mov    -0x30(%rbp),%rdi
lea    0xe7b(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1040 <fscanf@plt>
cmpl   $0xa,-0x24(%rbp)
jl     11ae <load_contacts+0x6e>
movl   $0xa,-0x24(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11ec <load_contacts+0xac>
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
imul   $0x14,%rax,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rdx
mov    $0x14,%esi
call   1050 <fgets@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11b5 <load_contacts+0x75>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    122d <load_contacts+0xed>
mov    -0x18(%rbp),%rdi
movslq -0x34(%rbp),%rax
imul   $0xc8,%rax,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rdx
mov    $0xc8,%esi
call   1050 <fgets@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11f3 <load_contacts+0xb3>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    126b <load_contacts+0x12b>
mov    -0x20(%rbp),%rdi
movslq -0x34(%rbp),%rax
imul   $0xa,%rax,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rdx
mov    $0xa,%esi
call   1050 <fgets@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1234 <load_contacts+0xf4>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_contacts>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
movl   $0x0,0xc(%rsp)
lea    0xe9b(%rip),%rdi
lea    0xea1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a0 <load_contacts+0x60>
mov    %rax,%r14
lea    0xe8f(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    0xc(%rsp),%eax
cmp    $0xa,%eax
jl     11a7 <load_contacts+0x67>
movl   $0xa,0xc(%rsp)
jmp    11af <load_contacts+0x6f>
xor    %eax,%eax
jmp    124e <load_contacts+0x10e>
test   %eax,%eax
jle    1242 <load_contacts+0x102>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x14,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0x14,%r13
cmp    %rax,%rbx
jl     11c0 <load_contacts+0x80>
test   %eax,%eax
jle    1242 <load_contacts+0x102>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0xc8,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0xc8,%r12
cmp    %rax,%rbx
jl     11f0 <load_contacts+0xb0>
test   %eax,%eax
jle    1242 <load_contacts+0x102>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0xa,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%rax
add    $0xa,%r15
cmp    %rax,%rbx
jl     1220 <load_contacts+0xe0>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"contacts.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @load_contacts([20 x i8]* %0, [200 x i8]* %1, [10 x i8]* %2) {
%4 = alloca i32
%5 = alloca [20 x i8]*
%6 = alloca [200 x i8]*
%7 = alloca [10 x i8]*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
store [20 x i8]* %0, [20 x i8]** %5
store [200 x i8]* %1, [200 x i8]** %6
store [10 x i8]* %2, [10 x i8]** %7
store i32 0, i32* %8
%11 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %9
%12 = load i32*, i32** %9
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 0, i32* %4
br label %73
15: ; preds = %3
%16 = load i32*, i32** %9
%17 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%18 = load i32, i32* %8
%19 = icmp sge i32 %18, 10
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 10, i32* %8
br label %21
21: ; preds = %20, %15
store i32 0, i32* %10
br label %22
22: ; preds = %34, %21
%23 = load i32, i32* %10
%24 = load i32, i32* %8
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %37
26: ; preds = %22
%27 = load [20 x i8]*, [20 x i8]** %5
%28 = load i32, i32* %10
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %27, i64 %29
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %30, i64 0, i64 0
%32 = load i32*, i32** %9
%33 = call i32 @fgets(i8* %31, i32 20, i32* %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %10
%36 = add nsw i32 %35, 1
store i32 %36, i32* %10
br label %22
37: ; preds = %22
store i32 0, i32* %10
br label %38
38: ; preds = %50, %37
%39 = load i32, i32* %10
%40 = load i32, i32* %8
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %53
42: ; preds = %38
%43 = load [200 x i8]*, [200 x i8]** %6
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [200 x i8], [200 x i8]* %43, i64 %45
%47 = getelementptr inbounds [200 x i8], [200 x i8]* %46, i64 0, i64 0
%48 = load i32*, i32** %9
%49 = call i32 @fgets(i8* %47, i32 200, i32* %48)
br label %50
50: ; preds = %42
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %38
53: ; preds = %38
store i32 0, i32* %10
br label %54
54: ; preds = %66, %53
%55 = load i32, i32* %10
%56 = load i32, i32* %8
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %69
58: ; preds = %54
%59 = load [10 x i8]*, [10 x i8]** %7
%60 = load i32, i32* %10
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [10 x i8], [10 x i8]* %59, i64 %61
%63 = getelementptr inbounds [10 x i8], [10 x i8]* %62, i64 0, i64 0
%64 = load i32*, i32** %9
%65 = call i32 @fgets(i8* %63, i32 10, i32* %64)
br label %66
66: ; preds = %58
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
store i32 %68, i32* %10
br label %54
69: ; preds = %54
%70 = load i32*, i32** %9
%71 = call i32 @fclose(i32* %70)
%72 = load i32, i32* %8
store i32 %72, i32* %4
br label %73
73: ; preds = %69, %14
%74 = load i32, i32* %4
ret i32 %74
}

LLVM IR (-O2):
@.str = [13 x i8] c"contacts.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @load_contacts([20 x i8]* %0, [200 x i8]* %1, [10 x i8]* %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %47, label %8
8: ; preds = %3
%9 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 9
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 10, i32* %4
br label %15
13: ; preds = %8
%14 = icmp sgt i32 %10, 0
br i1 %14, label %15, label %44
15: ; preds = %12, %13
br label %18
16: ; preds = %18
%17 = icmp sgt i32 %23, 0
br i1 %17, label %28, label %44
18: ; preds = %15, %18
%19 = phi i64 [ %22, %18 ], [ 0, %15 ]
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %0, i64 %19, i64 0
%21 = call i32 @fgets(i8* %20, i32 20, i32* %6)
%22 = add nuw nsw i64 %19, 1
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %22, %24
br i1 %25, label %18, label %16
26: ; preds = %28
%27 = icmp sgt i32 %33, 0
br i1 %27, label %36, label %44
28: ; preds = %16, %28
%29 = phi i64 [ %32, %28 ], [ 0, %16 ]
%30 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 %29, i64 0
%31 = call i32 @fgets(i8* %30, i32 200, i32* %6)
%32 = add nuw nsw i64 %29, 1
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %28, label %26
36: ; preds = %26, %36
%37 = phi i64 [ %40, %36 ], [ 0, %26 ]
%38 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 %37, i64 0
%39 = call i32 @fgets(i8* %38, i32 10, i32* %6)
%40 = add nuw nsw i64 %37, 1
%41 = load i32, i32* %4
%42 = sext i32 %41 to i64
%43 = icmp slt i64 %40, %42
br i1 %43, label %36, label %44
44: ; preds = %36, %13, %16, %26
%45 = call i32 @fclose(i32* %6)
%46 = load i32, i32* %4
br label %47
47: ; preds = %3, %44
%48 = phi i32 [ %46, %44 ], [ 0, %3 ]
ret i32 %48
}