#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 /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ walkdir(int /*<<< orphan*/ *, char *);
int main(int argc, char **argv) {
  FILE *index_file;
  if (argc == 1) {
    printf("Usage: %s indexfile\n", argv[0]);
    return 0;
  }
  if (!(index_file = fopen(argv[1], "w"))) {
    perror("error opening index file");
    return 1;
  }
  fprintf(index_file, "# tbaMUD mail index\n");
  fprintf(index_file, "# Format: <ID> <flags> <sender ID/vnum> <recipient ID> "
                      "<time> <subject>\n");
  fprintf(index_file, "# For 'No Subject', use (null)\n");
  walkdir(index_file, ".");
  fprintf(index_file, "~\n");
  fclose(index_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    119f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1239 <main+0xd9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe67(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11d9 <main+0x79>
lea    0xe4f(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1239 <main+0xd9>
mov    -0x18(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
lea    0xe9a(%rip),%rsi
call   1060 <walkdir@plt>
mov    -0x18(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jne    117a <main+0x1a>
mov    (%rsi),%rsi
lea    0xe90(%rip),%rdi
call   1040 <printf@plt>
jmp    1211 <main+0xb1>
mov    0x8(%rsi),%rdi
lea    0xe90(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1215 <main+0xb5>
mov    %rax,%rbx
lea    0xe93(%rip),%rdi
mov    $0x14,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
lea    0xe8f(%rip),%rdi
mov    $0x48,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xebf(%rip),%rdi
mov    $0x1f,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
lea    0xec6(%rip),%rsi
mov    %rbx,%rdi
call   1050 <walkdir@plt>
lea    0xeb9(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xdfb(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Usage: %s indexfile\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"error opening index file\00"
@.str.3 = [21 x i8] c"# tbaMUD mail index\0A\00"
@.str.4 = [73 x i8] c"# Format: <ID> <flags> <sender ID/vnum> <recipient ID> <time> <subject>\0A\00"
@.str.5 = [32 x i8] c"# For 'No Subject', use (null)\0A\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [3 x i8] c"~\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 0, i32* %3
br label %35
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %22, label %20
20: ; preds = %14
%21 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %35
22: ; preds = %14
%23 = load i32*, i32** %6
%24 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32*, i32** %6
%26 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32*, i32** %6
%28 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%29 = load i32*, i32** %6
%30 = call i32 @walkdir(i32* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%31 = load i32*, i32** %6
%32 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
store i32 0, i32* %3
br label %35
35: ; preds = %22, %20, %9
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [21 x i8] c"Usage: %s indexfile\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [25 x i8] c"error opening index file\00"
@.str.3 = [21 x i8] c"# tbaMUD mail index\0A\00"
@.str.4 = [73 x i8] c"# Format: <ID> <flags> <sender ID/vnum> <recipient ID> <time> <subject>\0A\00"
@.str.5 = [32 x i8] c"# For 'No Subject', use (null)\0A\00"
@.str.6 = [2 x i8] c".\00"
@.str.7 = [3 x i8] c"~\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %21
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %21
14: ; preds = %7
%15 = tail call i64 @fwrite(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 20, i64 1, i32* %10)
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.4, i64 0, i64 0), i64 72, i64 1, i32* %10)
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i64 31, i64 1, i32* %10)
%18 = tail call i32 @walkdir(i32* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%19 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 2, i64 1, i32* %10)
%20 = tail call i32 @fclose(i32* %10)
br label %21
21: ; preds = %14, %12, %4
%22 = phi i32 [ 0, %4 ], [ 0, %14 ], [ 1, %12 ]
ret i32 %22
}