#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*/ L_tmpnam;
int /*<<< orphan*/ check_bool(int, int /*<<< orphan*/);
int /*<<< orphan*/ check_int(int, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ int_sorter(char *);
int /*<<< orphan*/ read_int(int /*<<< orphan*/ *);
int /*<<< orphan*/ tmpnam(char *);
int /*<<< orphan*/ write_int(int /*<<< orphan*/ *, int);
int main() {
  {
    char tmpFileName[L_tmpnam + 1];
    tmpnam(tmpFileName);
    FILE *fp = fopen(tmpFileName, "wb");
    check_bool(true, write_int(fp, 1231));
    check_bool(true, write_int(fp, 1));
    check_bool(true, write_int(fp, 441));
    check_int(0, fclose(fp));
    int_sorter(tmpFileName);
    fp = fopen(tmpFileName, "rb");
    check_int(1, read_int(fp));
    check_int(441, read_int(fp));
    check_int(1231, read_int(fp));
    check_int(0, fclose(fp));
  }
  {
    char tmpFileName[L_tmpnam + 1];
    tmpnam(tmpFileName);
    FILE *fp = fopen(tmpFileName, "w");
    check_int(0, fclose(fp));
    int_sorter(tmpFileName);
  }
  { int_sorter("-------------- non existent file"); }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x2e51(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x8(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x10(%rbp)
call   10a0 <tmpnam@plt>
mov    -0x58(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x4cf,%esi
mov    %esi,-0x48(%rbp)
call   1050 <write_int@plt>
mov    %eax,%esi
mov    $0x1,%edi
mov    %edi,-0x50(%rbp)
call   1090 <check_bool@plt>
mov    -0x50(%rbp),%esi
mov    -0x18(%rbp),%rdi
call   1050 <write_int@plt>
mov    -0x50(%rbp),%edi
mov    %eax,%esi
call   1090 <check_bool@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1b9,%esi
mov    %esi,-0x4c(%rbp)
call   1050 <write_int@plt>
mov    -0x50(%rbp),%edi
mov    %eax,%esi
call   1090 <check_bool@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,%esi
xor    %edi,%edi
mov    %edi,-0x44(%rbp)
call   1040 <check_int@plt>
mov    -0x58(%rbp),%rdi
call   1070 <int_sorter@plt>
mov    -0x58(%rbp),%rdi
lea    0xdb5(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <read_int@plt>
mov    -0x50(%rbp),%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    -0x18(%rbp),%rdi
call   1060 <read_int@plt>
mov    -0x4c(%rbp),%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    -0x18(%rbp),%rdi
call   1060 <read_int@plt>
mov    -0x48(%rbp),%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x44(%rbp),%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    -0x40(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rsp
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
call   10a0 <tmpnam@plt>
mov    -0x38(%rbp),%rdi
lea    0xd20(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,%esi
xor    %edi,%edi
call   1040 <check_int@plt>
mov    -0x38(%rbp),%rdi
call   1070 <int_sorter@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
lea    0xcf0(%rip),%rdi
call   1070 <int_sorter@plt>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsp,%r12
mov    0x2e4b(%rip),%r15
mov    (%r15),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   10a0 <tmpnam@plt>
lea    0xe45(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x4cf,%esi
call   1050 <write_int@plt>
mov    $0x1,%edi
mov    %eax,%esi
call   1090 <check_bool@plt>
mov    %r14,%rdi
mov    $0x1,%esi
call   1050 <write_int@plt>
mov    $0x1,%edi
mov    %eax,%esi
call   1090 <check_bool@plt>
mov    %r14,%rdi
mov    $0x1b9,%esi
call   1050 <write_int@plt>
mov    $0x1,%edi
mov    %eax,%esi
call   1090 <check_bool@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    %rbx,%rdi
call   1070 <int_sorter@plt>
lea    0xdd2(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <read_int@plt>
mov    $0x1,%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    %rbx,%rdi
call   1060 <read_int@plt>
mov    $0x1b9,%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    %rbx,%rdi
call   1060 <read_int@plt>
mov    $0x4cf,%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    %r12,%rsp
mov    %rsp,%r14
mov    (%r15),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   10a0 <tmpnam@plt>
lea    0xd51(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    %rbx,%rdi
call   1070 <int_sorter@plt>
mov    %r14,%rsp
lea    0xd28(%rip),%rdi
call   1070 <int_sorter@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@L_tmpnam = global i32 0
@.str = [3 x i8] c"wb\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [33 x i8] c"-------------- non existent file\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = load i32, i32* @L_tmpnam
%8 = add nsw i32 %7, 1
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %1
%11 = alloca i8, i64 %9
store i64 %9, i64* %2
%12 = call i32 @tmpnam(i8* %11)
%13 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = call i32 @write_int(i32* %14, i32 1231)
%16 = call i32 @check_bool(i32 1, i32 %15)
%17 = load i32*, i32** %3
%18 = call i32 @write_int(i32* %17, i32 1)
%19 = call i32 @check_bool(i32 1, i32 %18)
%20 = load i32*, i32** %3
%21 = call i32 @write_int(i32* %20, i32 441)
%22 = call i32 @check_bool(i32 1, i32 %21)
%23 = load i32*, i32** %3
%24 = call i32 @fclose(i32* %23)
%25 = call i32 @check_int(i32 0, i32 %24)
%26 = call i32 @int_sorter(i8* %11)
%27 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %3
%28 = load i32*, i32** %3
%29 = call i32 @read_int(i32* %28)
%30 = call i32 @check_int(i32 1, i32 %29)
%31 = load i32*, i32** %3
%32 = call i32 @read_int(i32* %31)
%33 = call i32 @check_int(i32 441, i32 %32)
%34 = load i32*, i32** %3
%35 = call i32 @read_int(i32* %34)
%36 = call i32 @check_int(i32 1231, i32 %35)
%37 = load i32*, i32** %3
%38 = call i32 @fclose(i32* %37)
%39 = call i32 @check_int(i32 0, i32 %38)
%40 = load i8*, i8** %1
%41 = load i32, i32* @L_tmpnam
%42 = add nsw i32 %41, 1
%43 = zext i32 %42 to i64
%44 = call i8* @llvm.stacksave()
store i8* %44, i8** %4
%45 = alloca i8, i64 %43
store i64 %43, i64* %5
%46 = call i32 @tmpnam(i8* %45)
%47 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %47, i32** %6
%48 = load i32*, i32** %6
%49 = call i32 @fclose(i32* %48)
%50 = call i32 @check_int(i32 0, i32 %49)
%51 = call i32 @int_sorter(i8* %45)
%52 = load i8*, i8** %4
%53 = call i32 @int_sorter(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
@.str = [3 x i8] c"wb\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [33 x i8] c"-------------- non existent file\00"
define i32 @main() {
%1 = load i32, i32* @L_tmpnam
%2 = add nsw i32 %1, 1
%3 = zext i32 %2 to i64
%4 = tail call i8* @llvm.stacksave()
%5 = alloca i8, i64 %3
%6 = call i32 @tmpnam(i8* %5)
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @write_int(i32* %7, i32 1231)
%9 = call i32 @check_bool(i32 1, i32 %8)
%10 = call i32 @write_int(i32* %7, i32 1)
%11 = call i32 @check_bool(i32 1, i32 %10)
%12 = call i32 @write_int(i32* %7, i32 441)
%13 = call i32 @check_bool(i32 1, i32 %12)
%14 = call i32 @fclose(i32* %7)
%15 = call i32 @check_int(i32 0, i32 %14)
%16 = call i32 @int_sorter(i8* %5)
%17 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @read_int(i32* %17)
%19 = call i32 @check_int(i32 1, i32 %18)
%20 = call i32 @read_int(i32* %17)
%21 = call i32 @check_int(i32 441, i32 %20)
%22 = call i32 @read_int(i32* %17)
%23 = call i32 @check_int(i32 1231, i32 %22)
%24 = call i32 @fclose(i32* %17)
%25 = call i32 @check_int(i32 0, i32 %24)
%26 = load i32, i32* @L_tmpnam
%27 = add nsw i32 %26, 1
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
%30 = alloca i8, i64 %28
%31 = call i32 @tmpnam(i8* %30)
%32 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @fclose(i32* %32)
%34 = call i32 @check_int(i32 0, i32 %33)
%35 = call i32 @int_sorter(i8* %30)
%36 = call i32 @int_sorter(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}