#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*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int, char *,
                           double);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, unsigned int *, char *, double *);
int /*<<< orphan*/ stdin;
void fig11_02() {
  unsigned int account;
  char name[30];
  double balance;
  FILE *cfPtr;
  if ((cfPtr = fopen("clients.dat", "w")) == NULL) {
    puts("File could not be opened");
  } else {
    puts("Enter the account, name, and balance.");
    puts("Enter EOF to end input.");
    printf("%s", "? ");
    scanf("%d%29s%lf", &account, name, &balance);
    while (!feof(stdin)) {
      fprintf(cfPtr, "%d %s %.2f\n", account, name, balance);
      printf("%s", "? ");
      scanf("%d%29s%lf", &account, name, &balance);
    }
    fclose(cfPtr);
  }
}


x86 assembly (clang, -O0):
<fig11_02>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe81(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11aa <fig11_02+0x3a>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
jmp    1265 <fig11_02+0xf5>
lea    0xe76(%rip),%rdi
call   1030 <puts@plt>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9c(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdx
lea    0xe8b(%rip),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x38(%rbp),%rcx
call   1080 <scanf@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1210 <fig11_02+0xa0>
jmp    125c <fig11_02+0xec>
mov    -0x40(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    -0x30(%rbp),%rcx
movsd  -0x38(%rbp),%xmm0
lea    0xe4e(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe32(%rip),%rdi
lea    0xe2e(%rip),%rsi
call   1050 <printf@plt>
lea    -0x30(%rbp),%rdx
lea    0xe21(%rip),%rdi
lea    -0x4(%rbp),%rsi
lea    -0x38(%rbp),%rcx
call   1080 <scanf@plt>
jmp    11ed <fig11_02+0x7d>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig11_02>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xe7b(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1285 <fig11_02+0x115>
mov    %rax,%r15
lea    0xe83(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
lea    0xea9(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1050 <printf@plt>
lea    0xe9c(%rip),%rdi
lea    0x4(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   1080 <scanf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
test   %eax,%eax
jne    126e <fig11_02+0xfe>
lea    0x10(%rsp),%rbx
lea    0xe67(%rip),%r13
lea    0xe63(%rip),%rbp
lea    0x4(%rsp),%r14
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x4(%rsp),%edx
movsd  0x8(%rsp),%xmm0
mov    %r15,%rdi
lea    0xe41(%rip),%rsi
mov    %rbx,%rcx
call   1060 <fprintf@plt>
lea    0xe22(%rip),%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1080 <scanf@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
test   %eax,%eax
je     1220 <fig11_02+0xb0>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd82(%rip),%rdi
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"clients.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"File could not be opened\00"
@.str.3 = [38 x i8] c"Enter the account, name, and balance.\00"
@.str.4 = [24 x i8] c"Enter EOF to end input.\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [3 x i8] c"? \00"
@.str.7 = [10 x i8] c"%d%29s%lf\00"
@stdin = global i32 0
@.str.8 = [12 x i8] c"%d %s %.2f\0A\00"
define void @fig11_02() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca double
%4 = alloca i32*
%5 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %4
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %32
9: ; preds = %0
%10 = call i32 @puts(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%14 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32* %1, i8* %13, double* %3)
br label %15
15: ; preds = %20, %9
%16 = load i32, i32* @stdin
%17 = call i32 @feof(i32 %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %29
20: ; preds = %15
%21 = load i32*, i32** %4
%22 = load i32, i32* %1
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%24 = load double, double* %3
%25 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %22, i8* %23, double %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%27 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%28 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32* %1, i8* %27, double* %3)
br label %15
29: ; preds = %15
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
br label %32
32: ; preds = %29, %7
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"clients.dat\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"File could not be opened\00"
@.str.3 = [38 x i8] c"Enter the account, name, and balance.\00"
@.str.4 = [24 x i8] c"Enter EOF to end input.\00"
@.str.5 = [3 x i8] c"%s\00"
@.str.6 = [3 x i8] c"? \00"
@.str.7 = [10 x i8] c"%d%29s%lf\00"
@stdin = global i32 0
@.str.8 = [12 x i8] c"%d %s %.2f\0A\00"
define void @fig11_02() {
%1 = alloca i32
%2 = alloca [30 x i8]
%3 = alloca double
%4 = bitcast i32* %1 to i8*
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%6 = bitcast double* %3 to i8*
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %30
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%14 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32* %1, i8* %5, double* %3)
%16 = load i32, i32* @stdin
%17 = call i32 @feof(i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %11, %19
%20 = load i32, i32* %1
%21 = load double, double* %3
%22 = call i32 @fprintf(i32* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %20, i8* %5, double %21)
%23 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32* %1, i8* %5, double* %3)
%25 = load i32, i32* @stdin
%26 = call i32 @feof(i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %19, label %28
28: ; preds = %19, %11
%29 = call i32 @fclose(i32* %7)
br label %30
30: ; preds = %28, %9
ret void
}