#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 */
scalar_t__ EOF;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int tf(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  FILE *fp = NULL;
  if (argc != 2) {
    fputs("tf: usage: tf <output file>\n", stderr);
    return 1;
  }
  fp = fopen(*++argv, "w");
  if (fp == NULL) {
    perror("fopen");
    fputs("tf: opening output file failed.\n", stderr);
    return 1;
  }
  if (tf(fp) == 1) {
    fputs("tf: writing into output file failed.\n", stderr);
    (void)fclose(fp);
    return 1;
  }
  if (fclose(fp) == EOF) {
    perror("tf: fclose");
    fputs("tf: closing output file failed.\n", stderr);
    return 1;
  }
  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)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1199 <main+0x49>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    127d <main+0x12d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f4 <main+0xa4>
lea    0xe51(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
lea    0xe42(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    127d <main+0x12d>
mov    -0x18(%rbp),%rdi
call   1070 <tf@plt>
cmp    $0x1,%eax
jne    1230 <main+0xe0>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
lea    0xe30(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    127d <main+0x12d>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2da8(%rip),%rcx
cmp    (%rcx),%rax
jne    1276 <main+0x126>
lea    0xe1c(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
lea    0xe12(%rip),%rdi
call   1040 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    127d <main+0x12d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x2,%edi
jne    119a <main+0x4a>
mov    0x8(%rsi),%rdi
lea    0xebc(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11d1 <main+0x81>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <tf@plt>
cmp    $0x1,%eax
jne    11b6 <main+0x66>
mov    0x2e56(%rip),%rax
mov    (%rax),%esi
lea    0xebb(%rip),%rdi
call   1040 <fputs@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11af <main+0x5f>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    0xe56(%rip),%rdi
call   1040 <fputs@plt>
mov    $0x1,%eax
jmp    11cf <main+0x7f>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %rax,%rcx
mov    0x2e20(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     11ef <main+0x9f>
pop    %rbx
ret
lea    0xe47(%rip),%rdi
call   1060 <perror@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
lea    0xe38(%rip),%rdi
jmp    11aa <main+0x5a>
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    0xe6c(%rip),%rdi
jmp    11aa <main+0x5a>

LLVM IR (-O0):
@.str = [29 x i8] c"tf: usage: tf <output file>\0A\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [33 x i8] c"tf: opening output file failed.\0A\00"
@.str.4 = [38 x i8] c"tf: writing into output file failed.\0A\00"
@EOF = global i64 0
@.str.5 = [11 x i8] c"tf: fclose\00"
@.str.6 = [33 x i8] c"tf: closing output file failed.\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
store i32* null, i32** %6
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fputs(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 1, i32* %3
br label %42
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i32 1
store i8** %14, i8*** %5
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %21)
store i32 1, i32* %3
br label %42
23: ; preds = %12
%24 = load i32*, i32** %6
%25 = call i32 @tf(i32* %24)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 @fputs(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = load i32*, i32** %6
%31 = call i64 @fclose(i32* %30)
store i32 1, i32* %3
br label %42
32: ; preds = %23
%33 = load i32*, i32** %6
%34 = call i64 @fclose(i32* %33)
%35 = load i64, i64* @EOF
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %41
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %39)
store i32 1, i32* %3
br label %42
41: ; preds = %32
store i32 0, i32* %3
br label %42
42: ; preds = %41, %37, %27, %19, %9
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [29 x i8] c"tf: usage: tf <output file>\0A\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [33 x i8] c"tf: opening output file failed.\0A\00"
@.str.4 = [38 x i8] c"tf: writing into output file failed.\0A\00"
@EOF = global i64 0
@.str.5 = [11 x i8] c"tf: fclose\00"
@.str.6 = [33 x i8] c"tf: closing output file failed.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %31
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 %16
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = tail call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %14)
br label %31
16: ; preds = %7
%17 = tail call i32 @tf(i32* %10)
%18 = icmp eq i32 %17, 1
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = tail call i32 @fputs(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = tail call i64 @fclose(i32* %10)
br label %31
23: ; preds = %16
%24 = tail call i64 @fclose(i32* %10)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%29 = load i32, i32* @stderr
%30 = tail call i32 @fputs(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %23, %27, %19, %12, %4
%32 = phi i32 [ 1, %4 ], [ 1, %12 ], [ 1, %19 ], [ 1, %27 ], [ 0, %23 ]
ret i32 %32
}