#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 */
struct stNameTableProcessor {
  int dummy;
};
struct stNameTable {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char *append(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int nameTableProcessorWrite(struct stNameTableProcessor *, struct stNameTable *,
                            int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int writeNameTable(struct stNameTableProcessor *nameTableProcessor,
                   struct stNameTable *nameTable, char *pcxFilename,
                   int verbose) {
  int i = 0;
  char *namFilename = NULL;
  FILE *namFile = NULL;
  namFilename = append(pcxFilename, ".nam");
  if (verbose)
    printf("Writing output file %s...\n", namFilename);
  if (!(namFile = fopen(namFilename, "wb"))) {
    printf("ERROR: Could not create %s.\n", namFilename);
    i = 41;
    goto out;
  }
  if ((i = nameTableProcessorWrite(nameTableProcessor, nameTable, namFile))) {
    printf("ERROR: Failed writing %s.\n", namFilename);
    goto out;
  }
out:
  if (namFilename)
    free(namFilename);
  if (namFile)
    fclose(namFile);
  return i;
}


x86 assembly (clang, -O0):
<writeNameTable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe67(%rip),%rsi
call   1040 <append@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11bc <writeNameTable+0x5c>
mov    -0x28(%rbp),%rsi
lea    0xe4e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11f6 <writeNameTable+0x96>
mov    -0x28(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1060 <printf@plt>
movl   $0x29,-0x20(%rbp)
jmp    122d <writeNameTable+0xcd>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <nameTableProcessorWrite@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
je     1228 <writeNameTable+0xc8>
mov    -0x28(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1060 <printf@plt>
jmp    122d <writeNameTable+0xcd>
jmp    122d <writeNameTable+0xcd>
cmpq   $0x0,-0x28(%rbp)
je     1241 <writeNameTable+0xe1>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x30(%rbp)
je     1255 <writeNameTable+0xf5>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeNameTable>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe89(%rip),%rsi
mov    %rdx,%rdi
call   1040 <append@plt>
mov    %rax,%rbx
test   %ebp,%ebp
je     1195 <writeNameTable+0x35>
lea    0xe78(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     11c9 <writeNameTable+0x69>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1070 <nameTableProcessorWrite@plt>
test   %eax,%eax
je     1202 <writeNameTable+0xa2>
mov    %eax,%ebp
lea    0xe79(%rip),%rdi
jmp    11d5 <writeNameTable+0x75>
mov    $0x29,%ebp
lea    0xe4e(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
test   %rbx,%rbx
je     11ea <writeNameTable+0x8a>
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     11f7 <writeNameTable+0x97>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
test   %rbx,%rbx
jne    11e2 <writeNameTable+0x82>
jmp    11ea <writeNameTable+0x8a>

LLVM IR (-O0):
%struct.stNameTableProcessor = type { i32 }
%struct.stNameTable = type { i32 }
@.str = [5 x i8] c".nam\00"
@.str.1 = [27 x i8] c"Writing output file %s...\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [29 x i8] c"ERROR: Could not create %s.\0A\00"
@.str.4 = [27 x i8] c"ERROR: Failed writing %s.\0A\00"
define i32 @writeNameTable(%struct.stNameTableProcessor* %0, %struct.stNameTable* %1, i8* %2, i32 %3) {
%5 = alloca %struct.stNameTableProcessor*
%6 = alloca %struct.stNameTable*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32*
store %struct.stNameTableProcessor* %0, %struct.stNameTableProcessor** %5
store %struct.stNameTable* %1, %struct.stNameTable** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store i32 0, i32* %9
store i8* null, i8** %10
store i32* null, i32** %11
%12 = load i8*, i8** %7
%13 = call i8* @append(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %13, i8** %10
%14 = load i32, i32* %8
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %4
%17 = load i8*, i8** %10
%18 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %4
%20 = load i8*, i8** %10
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %21, i32** %11
%22 = icmp ne i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = load i8*, i8** %10
%25 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %24)
store i32 41, i32* %9
br label %36
26: ; preds = %19
%27 = load %struct.stNameTableProcessor*, %struct.stNameTableProcessor** %5
%28 = load %struct.stNameTable*, %struct.stNameTable** %6
%29 = load i32*, i32** %11
%30 = call i32 @nameTableProcessorWrite(%struct.stNameTableProcessor* %27, %struct.stNameTable* %28, i32* %29)
store i32 %30, i32* %9
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i8*, i8** %10
%34 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %33)
br label %36
35: ; preds = %26
br label %36
36: ; preds = %35, %32, %23
%37 = load i8*, i8** %10
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i8*, i8** %10
%41 = call i32 @free(i8* %40)
br label %42
42: ; preds = %39, %36
%43 = load i32*, i32** %11
%44 = icmp ne i32* %43, null
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i32*, i32** %11
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %45, %42
%49 = load i32, i32* %9
ret i32 %49
}

LLVM IR (-O2):
%struct.stNameTableProcessor = type { i32 }
%struct.stNameTable = type { i32 }
@.str = [5 x i8] c".nam\00"
@.str.1 = [27 x i8] c"Writing output file %s...\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [29 x i8] c"ERROR: Could not create %s.\0A\00"
@.str.4 = [27 x i8] c"ERROR: Failed writing %s.\0A\00"
define i32 @writeNameTable(%struct.stNameTableProcessor* %0, %struct.stNameTable* %1, i8* %2, i32 %3) {
%5 = tail call i8* @append(i8* %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %3, 0
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %9
9: ; preds = %7, %4
%10 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = tail call i32 @nameTableProcessorWrite(%struct.stNameTableProcessor* %0, %struct.stNameTable* %1, i32* %10)
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %12, %9
%16 = phi i8* [ getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), %9 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), %12 ]
%17 = phi i32 [ 41, %9 ], [ %13, %12 ]
%18 = tail call i32 @printf(i8* %16, i8* %5)
br label %19
19: ; preds = %15, %12
%20 = phi i32 [ 0, %12 ], [ %17, %15 ]
%21 = icmp eq i8* %5, null
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 @free(i8* %5)
br label %24
24: ; preds = %22, %19
br i1 %11, label %27, label %25
25: ; preds = %24
%26 = tail call i32 @fclose(i32* %10)
br label %27
27: ; preds = %25, %24
ret i32 %20
}