#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);
  }
  for (i = 0; i < numItems; i++) {
    fputs(addresses[i], outfile);
  }
  for (i = 0; i < numItems; i++) {
    fputs(phoneNumbers[i], 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    1248 <save_contacts+0x108>
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    11ca <save_contacts+0x8a>
mov    -0x8(%rbp),%rdi
movslq -0x2c(%rbp),%rax
imul   $0x14,%rax,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
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    1206 <save_contacts+0xc6>
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
imul   $0xc8,%rax,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d1 <save_contacts+0x91>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    123f <save_contacts+0xff>
mov    -0x18(%rbp),%rdi
movslq -0x2c(%rbp),%rax
imul   $0xa,%rax,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    120d <save_contacts+0xcd>
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,%r12
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xea2(%rip),%rdi
lea    0xea8(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     121b <save_contacts+0xdb>
mov    %rax,%r14
lea    0xe92(%rip),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
call   1050 <fprintf@plt>
test   %r15d,%r15d
jle    1205 <save_contacts+0xc5>
mov    %r15d,0x4(%rsp)
mov    %r15d,%r15d
mov    %r15,%r13
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
add    $0x14,%rbx
add    $0xffffffffffffffff,%r13
jne    11a0 <save_contacts+0x60>
mov    0x4(%rsp),%r13d
test   %r13d,%r13d
jle    1205 <save_contacts+0xc5>
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
add    $0xc8,%rbp
add    $0xffffffffffffffff,%rbx
jne    11d0 <save_contacts+0x90>
test   %r13d,%r13d
jle    1205 <save_contacts+0xc5>
nopl   (%rax)
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
add    $0xa,%r12
add    $0xffffffffffffffff,%r15
jne    11f0 <save_contacts+0xb0>
mov    %r14,%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"
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 %69
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 = %31, %15
%20 = load i32, i32* %10
%21 = load i32, i32* %8
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %34
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)
br label %31
31: ; preds = %23
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
store i32 %33, i32* %10
br label %19
34: ; preds = %19
store i32 0, i32* %10
br label %35
35: ; preds = %47, %34
%36 = load i32, i32* %10
%37 = load i32, i32* %8
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = load [200 x i8]*, [200 x i8]** %6
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [200 x i8], [200 x i8]* %40, i64 %42
%44 = getelementptr inbounds [200 x i8], [200 x i8]* %43, i64 0, i64 0
%45 = load i32*, i32** %9
%46 = call i32 @fputs(i8* %44, i32* %45)
br label %47
47: ; preds = %39
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
br label %35
50: ; preds = %35
store i32 0, i32* %10
br label %51
51: ; preds = %63, %50
%52 = load i32, i32* %10
%53 = load i32, i32* %8
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %66
55: ; preds = %51
%56 = load [10 x i8]*, [10 x i8]** %7
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %56, i64 %58
%60 = getelementptr inbounds [10 x i8], [10 x i8]* %59, i64 0, i64 0
%61 = load i32*, i32** %9
%62 = call i32 @fputs(i8* %60, i32* %61)
br label %63
63: ; preds = %55
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %51
66: ; preds = %51
%67 = load i32*, i32** %9
%68 = call i32 @fclose(i32* %67)
br label %69
69: ; preds = %66, %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 %38, 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 %36
10: ; preds = %7
%11 = zext i32 %3 to i64
br label %15
12: ; preds = %15
br i1 %9, label %13, label %36
13: ; preds = %12
%14 = zext i32 %3 to i64
br label %24
15: ; preds = %10, %15
%16 = phi i64 [ 0, %10 ], [ %19, %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 = add nuw nsw i64 %16, 1
%20 = icmp eq i64 %19, %11
br i1 %20, label %12, label %15
21: ; preds = %24
br i1 %9, label %22, label %36
22: ; preds = %21
%23 = zext i32 %3 to i64
br label %30
24: ; preds = %13, %24
%25 = phi i64 [ 0, %13 ], [ %28, %24 ]
%26 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 %25, i64 0
%27 = tail call i32 @fputs(i8* %26, i32* %5)
%28 = add nuw nsw i64 %25, 1
%29 = icmp eq i64 %28, %14
br i1 %29, label %21, label %24
30: ; preds = %22, %30
%31 = phi i64 [ 0, %22 ], [ %34, %30 ]
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 %31, i64 0
%33 = tail call i32 @fputs(i8* %32, i32* %5)
%34 = add nuw nsw i64 %31, 1
%35 = icmp eq i64 %34, %23
br i1 %35, label %36, label %30
36: ; preds = %30, %7, %12, %21
%37 = tail call i32 @fclose(i32* %5)
br label %38
38: ; preds = %4, %36
ret void
}