#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 L_tmpnam;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ test2(int /*<<< orphan*/ *, int, double, long, char, char *,
                         int, int, int);
char *tmpnam(char *);
int /*<<< orphan*/ unlink(char *);
int main() {
  char name[L_tmpnam];
  FILE *file = fopen(tmpnam(name), "w");
  if (file == NULL) {
    printf("Failed to open file\n");
    abort();
  }
  test2(file, 1, 2.3, 3L, 'a', "asdf", 123, 3242, -5);
  fclose(file);
  FILE *read = fopen(name, "r");
  if (read == NULL) {
    printf("Failed to open file\n");
    abort();
  }
  char buf[20];
  while (fgets(buf, 20, read) != NULL) {
    printf("%s\n", buf);
  }
  fclose(read);
  unlink(name);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
call   10a0 <tmpnam@plt>
mov    %rax,%rdi
lea    0xe3e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f3 <main+0x73>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
movsd  0xdfc(%rip),%xmm0
mov    $0x3,%edx
mov    $0x61,%ecx
lea    0xe0a(%rip),%r8
mov    $0x7b,%r9d
sub    $0x10,%rsp
movl   $0xcaa,(%rsp)
movl   $0xfffffffb,0x8(%rsp)
ff
call   1080 <test2@plt>
add    $0x10,%rsp
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x48(%rbp),%rdi
lea    0xdd9(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1274 <main+0xf4>
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1279 <main+0xf9>
lea    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x14,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12ac <main+0x12c>
lea    -0x40(%rbp),%rsi
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1279 <main+0xf9>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
call   10a0 <tmpnam@plt>
lea    0xe52(%rip),%rsi
mov    %rax,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     127a <main+0xfa>
mov    %rax,%rbx
lea    0xe39(%rip),%r8
movsd  0xe27(%rip),%xmm0
mov    $0x3,%edx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x61,%ecx
mov    $0x7b,%r9d
push   $0xfffffffffffffffb
push   $0xcaa
call   1080 <test2@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1060 <fclose@plt>
lea    0xdff(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     127a <main+0xfa>
mov    %rax,%r15
lea    -0x30(%rbp),%rdi
mov    $0x14,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     125d <main+0xdd>
lea    -0x30(%rbp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
mov    $0x14,%esi
mov    %r15,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1240 <main+0xc0>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1040 <unlink@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd90(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@L_tmpnam = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [21 x i8] c"Failed to open file\0A\00"
@.str.2 = [5 x i8] c"asdf\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [20 x i8]
store i32 0, i32* %1
%7 = load i32, i32* @L_tmpnam
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %2
%10 = alloca i8, i64 %8
store i64 %8, i64* %3
%11 = call i8* @tmpnam(i8* %10)
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %4
%13 = load i32*, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %0
%19 = load i32*, i32** %4
%20 = call i32 @test2(i32* %19, i32 1, double 2.300000e+00, i64 3, i8 signext 97, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 123, i32 3242, i32 -5)
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
%23 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %23, i32** %5
%24 = load i32*, i32** %5
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 (...) @abort()
unreachable
29: ; preds = %18
br label %30
30: ; preds = %35, %29
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%32 = load i32*, i32** %5
%33 = call i32* @fgets(i8* %31, i32 20, i32* %32)
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %36)
br label %30
38: ; preds = %30
%39 = load i32*, i32** %5
%40 = call i32 @fclose(i32* %39)
%41 = call i32 @unlink(i8* %10)
%42 = load i8*, i8** %2
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
@.str = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"asdf\00"
@.str.3 = [2 x i8] c"r\00"
@str.5 = [20 x i8] c"Failed to open file\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = load i32, i32* @L_tmpnam
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i8* @tmpnam(i8* %4)
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %0
%12 = call i32 @test2(i32* %6, i32 1, double 2.300000e+00, i64 3, i8 signext 97, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 123, i32 3242, i32 -5)
%13 = call i32 @fclose(i32* %6)
%14 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0))
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %11
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%21 = call i32* @fgets(i8* %20, i32 20, i32* %14)
%22 = icmp eq i32* %21, null
br i1 %22, label %27, label %23
23: ; preds = %19, %23
%24 = call i32 @puts(i8* %20)
%25 = call i32* @fgets(i8* %20, i32 20, i32* %14)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %23
27: ; preds = %23, %19
%28 = call i32 @fclose(i32* %14)
%29 = call i32 @unlink(i8* %4)
ret i32 0
}