#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 /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, ...);
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++) {
    fscanf(infile, "%s", names[i]);
  }
  for (i = 0; i < numItems; i++) {
    fscanf(infile, "%s", addresses[i]);
  }
  for (i = 0; i < numItems; i++) {
    fscanf(infile, "%s", phoneNumbers[i]);
  }
  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    0xeae(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1179 <load_contacts+0x49>
movl   $0x0,-0x4(%rbp)
jmp    1278 <load_contacts+0x148>
mov    -0x30(%rbp),%rdi
lea    0xe8b(%rip),%rsi
lea    -0x24(%rbp),%rdx
mov    $0x0,%al
call   1040 <fscanf@plt>
cmpl   $0xa,-0x24(%rbp)
jl     11a0 <load_contacts+0x70>
movl   $0xa,-0x24(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11e2 <load_contacts+0xb2>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
movslq -0x34(%rbp),%rax
imul   $0x14,%rax,%rax
add    %rax,%rdx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11a7 <load_contacts+0x77>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1227 <load_contacts+0xf7>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rdx
movslq -0x34(%rbp),%rax
imul   $0xc8,%rax,%rax
add    %rax,%rdx
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e9 <load_contacts+0xb9>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1269 <load_contacts+0x139>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
movslq -0x34(%rbp),%rax
imul   $0xa,%rax,%rax
add    %rax,%rdx
lea    0xdbe(%rip),%rsi
mov    $0x0,%al
call   1040 <fscanf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    122e <load_contacts+0xfe>
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   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
movl   $0x0,0x4(%rsp)
lea    0xead(%rip),%rdi
lea    0xeb3(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1190 <load_contacts+0x60>
mov    %rax,%r14
lea    0xea1(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1040 <fscanf@plt>
mov    0x4(%rsp),%eax
cmp    $0xa,%eax
jl     1197 <load_contacts+0x67>
movl   $0xa,0x4(%rsp)
jmp    119f <load_contacts+0x6f>
xor    %eax,%eax
jmp    124e <load_contacts+0x11e>
test   %eax,%eax
jle    1242 <load_contacts+0x112>
lea    0xe6c(%rip),%r13
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
add    $0x14,%rbx
cmp    %rax,%rbp
jl     11b0 <load_contacts+0x80>
test   %eax,%eax
jle    1242 <load_contacts+0x112>
lea    0xe35(%rip),%rbx
xor    %ebp,%ebp
nop
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
add    $0xc8,%r12
cmp    %rax,%rbp
jl     11e0 <load_contacts+0xb0>
test   %eax,%eax
jle    1242 <load_contacts+0x112>
lea    0xe02(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fscanf@plt>
add    $0x1,%rbp
movslq 0x4(%rsp),%rax
add    $0xa,%r15
cmp    %rax,%rbp
jl     1220 <load_contacts+0xf0>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
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"
@.str.3 = [3 x i8] c"%s\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 (i32*, i8*, ...) @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 i32*, i32** %9
%28 = load [20 x i8]*, [20 x i8]** %5
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %28, i64 %30
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %31, i64 0, i64 0
%33 = call i32 (i32*, i8*, ...) @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %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 i32*, i32** %9
%44 = load [200 x i8]*, [200 x i8]** %6
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [200 x i8], [200 x i8]* %44, i64 %46
%48 = getelementptr inbounds [200 x i8], [200 x i8]* %47, i64 0, i64 0
%49 = call i32 (i32*, i8*, ...) @fscanf(i32* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %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 i32*, i32** %9
%60 = load [10 x i8]*, [10 x i8]** %7
%61 = load i32, i32* %10
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [10 x i8], [10 x i8]* %60, i64 %62
%64 = getelementptr inbounds [10 x i8], [10 x i8]* %63, i64 0, i64 0
%65 = call i32 (i32*, i8*, ...) @fscanf(i32* %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %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"
@.str.3 = [3 x i8] c"%s\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 (i32*, i8*, ...) @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 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%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 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%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 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%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
}