#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*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
void save_contacts(char names[10][20], char addresses[10][200],
                   char phoneNumbers[10][10], int numItems) {
  FILE *outfile = fopen("contacts.dat", "w");
  if (outfile == NULL) {
    return;
  }
  fprintf(outfile, "%d", numItems);
  int i;
  for (i = 0; i < numItems; i++) {
    fputs(names[i], outfile);
    fputs("\n", outfile);
  }
  for (i = 0; i < numItems; i++) {
    fputs(addresses[i], outfile);
    fputs("\n", outfile);
  }
  for (i = 0; i < numItems; i++) {
    fputs(phoneNumbers[i], outfile);
    fputs("\n", outfile);
  }
  fclose(outfile);
}


x86 assembly (clang, -O0):
<save_contacts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
lea    0xea2(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    117e <save_contacts+0x3e>
jmp    1278 <save_contacts+0x138>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe83(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11da <save_contacts+0x9a>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
imul   $0x14,%rax,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x28(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1198 <save_contacts+0x58>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1226 <save_contacts+0xe6>
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
imul   $0xc8,%rax,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x28(%rbp),%rsi
lea    0xdff(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11e1 <save_contacts+0xa1>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    126f <save_contacts+0x12f>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
imul   $0xa,%rax,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x28(%rbp),%rsi
lea    0xdb6(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    122d <save_contacts+0xed>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_contacts>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe92(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1248 <save_contacts+0xf8>
mov    %rax,%r12
lea    0xe82(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
call   1060 <fprintf@plt>
test   %r15d,%r15d
jle    1232 <save_contacts+0xe2>
mov    %r15d,0x4(%rsp)
mov    %r15d,%r15d
mov    %r15,%r13
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
mov    $0xa,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
add    $0x14,%rbx
add    $0xffffffffffffffff,%r13
jne    11b0 <save_contacts+0x60>
mov    0x4(%rsp),%r13d
test   %r13d,%r13d
jle    1232 <save_contacts+0xe2>
mov    %r15,%rbx
nop
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
mov    $0xa,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
add    $0xc8,%rbp
add    $0xffffffffffffffff,%rbx
jne    11e0 <save_contacts+0x90>
test   %r13d,%r13d
jle    1232 <save_contacts+0xe2>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <fputs@plt>
mov    $0xa,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
add    $0xa,%r14
add    $0xffffffffffffffff,%r15
jne    1210 <save_contacts+0xc0>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
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"w\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @save_contacts([20 x i8]* %0, [200 x i8]* %1, [10 x i8]* %2, i32 %3) {
%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 %3, 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 = %4
br label %75
15: ; preds = %4
%16 = load i32*, i32** %9
%17 = load i32, i32* %8
%18 = call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %17)
store i32 0, i32* %10
br label %19
19: ; preds = %33, %15
%20 = load i32, i32* %10
%21 = load i32, i32* %8
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %36
23: ; preds = %19
%24 = load [20 x i8]*, [20 x i8]** %5
%25 = load i32, i32* %10
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %24, i64 %26
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %27, i64 0, i64 0
%29 = load i32*, i32** %9
%30 = call i32 @fputs(i8* %28, i32* %29)
%31 = load i32*, i32** %9
%32 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* %31)
br label %33
33: ; preds = %23
%34 = load i32, i32* %10
%35 = add nsw i32 %34, 1
store i32 %35, i32* %10
br label %19
36: ; preds = %19
store i32 0, i32* %10
br label %37
37: ; preds = %51, %36
%38 = load i32, i32* %10
%39 = load i32, i32* %8
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %54
41: ; preds = %37
%42 = load [200 x i8]*, [200 x i8]** %6
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [200 x i8], [200 x i8]* %42, i64 %44
%46 = getelementptr inbounds [200 x i8], [200 x i8]* %45, i64 0, i64 0
%47 = load i32*, i32** %9
%48 = call i32 @fputs(i8* %46, i32* %47)
%49 = load i32*, i32** %9
%50 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* %49)
br label %51
51: ; preds = %41
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
br label %37
54: ; preds = %37
store i32 0, i32* %10
br label %55
55: ; preds = %69, %54
%56 = load i32, i32* %10
%57 = load i32, i32* %8
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %72
59: ; preds = %55
%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 = load i32*, i32** %9
%66 = call i32 @fputs(i8* %64, i32* %65)
%67 = load i32*, i32** %9
%68 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32* %67)
br label %69
69: ; preds = %59
%70 = load i32, i32* %10
%71 = add nsw i32 %70, 1
store i32 %71, i32* %10
br label %55
72: ; preds = %55
%73 = load i32*, i32** %9
%74 = call i32 @fclose(i32* %73)
br label %75
75: ; preds = %72, %14
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"contacts.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [3 x i8] c"%d\00"
define void @save_contacts([20 x i8]* nocapture %0, [200 x i8]* nocapture %1, [10 x i8]* nocapture %2, i32 %3) {
%5 = 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))
%6 = icmp eq i32* %5, null
br i1 %6, label %41, label %7
7: ; preds = %4
%8 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%9 = icmp sgt i32 %3, 0
br i1 %9, label %10, label %39
10: ; preds = %7
%11 = zext i32 %3 to i64
br label %15
12: ; preds = %15
br i1 %9, label %13, label %39
13: ; preds = %12
%14 = zext i32 %3 to i64
br label %25
15: ; preds = %10, %15
%16 = phi i64 [ 0, %10 ], [ %20, %15 ]
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %0, i64 %16, i64 0
%18 = tail call i32 @fputs(i8* %17, i32* %5)
%19 = tail call i32 @fputc(i32 10, i32* %5)
%20 = add nuw nsw i64 %16, 1
%21 = icmp eq i64 %20, %11
br i1 %21, label %12, label %15
22: ; preds = %25
br i1 %9, label %23, label %39
23: ; preds = %22
%24 = zext i32 %3 to i64
br label %32
25: ; preds = %13, %25
%26 = phi i64 [ 0, %13 ], [ %30, %25 ]
%27 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 %26, i64 0
%28 = tail call i32 @fputs(i8* %27, i32* %5)
%29 = tail call i32 @fputc(i32 10, i32* %5)
%30 = add nuw nsw i64 %26, 1
%31 = icmp eq i64 %30, %14
br i1 %31, label %22, label %25
32: ; preds = %23, %32
%33 = phi i64 [ 0, %23 ], [ %37, %32 ]
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 %33, i64 0
%35 = tail call i32 @fputs(i8* %34, i32* %5)
%36 = tail call i32 @fputc(i32 10, i32* %5)
%37 = add nuw nsw i64 %33, 1
%38 = icmp eq i64 %37, %24
br i1 %38, label %39, label %32
39: ; preds = %32, %7, %12, %22
%40 = tail call i32 @fclose(i32* %5)
br label %41
41: ; preds = %4, %39
ret void
}