#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_int(int, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ range(char *);
int /*<<< orphan*/ tmpnam(char *);
int main() {
  {
    char tmpFileName[L_tmpnam + 1];
    tmpnam(tmpFileName);
    FILE *fp = fopen(tmpFileName, "w");
    fputs("1231\n", fp);
    fputs("1\n", fp);
    fputs("441\n", fp);
    check_int(0, fclose(fp));
    check_int(1230, range(tmpFileName));
  }
  {
    char tmpFileName[L_tmpnam + 1];
    tmpnam(tmpFileName);
    FILE *fp = fopen(tmpFileName, "w");
    check_int(0, fclose(fp));
    check_int(1, range(tmpFileName));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x2e71(%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,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x10(%rbp)
call   1080 <tmpnam@plt>
mov    -0x48(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe43(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rsi
lea    0xe36(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    %eax,%esi
xor    %edi,%edi
call   1040 <check_int@plt>
mov    -0x48(%rbp),%rdi
call   1060 <range@plt>
mov    %eax,%esi
mov    $0x4ce,%edi
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   1080 <tmpnam@plt>
mov    -0x38(%rbp),%rdi
lea    0xdb2(%rip),%rsi
call   1070 <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   1060 <range@plt>
mov    %eax,%esi
mov    $0x1,%edi
call   1040 <check_int@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsp,%r13
mov    0x2e68(%rip),%r12
mov    (%r12),%eax
add    $0x1,%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    %r15,%rdi
call   1080 <tmpnam@plt>
lea    0xe61(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe4e(%rip),%rdi
mov    $0x5,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1070 <fwrite@plt>
lea    0xe38(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
lea    0xe22(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    %r15,%rdi
call   1050 <range@plt>
mov    $0x4ce,%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    %r13,%rsp
mov    (%r12),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1080 <tmpnam@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1040 <check_int@plt>
mov    %rbx,%rdi
call   1050 <range@plt>
mov    $0x1,%edi
mov    %eax,%esi
call   1040 <check_int@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@L_tmpnam = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [6 x i8] c"1231\0A\00"
@.str.2 = [3 x i8] c"1\0A\00"
@.str.3 = [5 x i8] c"441\0A\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 ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %14)
%16 = load i32*, i32** %3
%17 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %16)
%18 = load i32*, i32** %3
%19 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %18)
%20 = load i32*, i32** %3
%21 = call i32 @fclose(i32* %20)
%22 = call i32 @check_int(i32 0, i32 %21)
%23 = call i32 @range(i8* %11)
%24 = call i32 @check_int(i32 1230, i32 %23)
%25 = load i8*, i8** %1
%26 = load i32, i32* @L_tmpnam
%27 = add nsw i32 %26, 1
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %4
%30 = alloca i8, i64 %28
store i64 %28, i64* %5
%31 = call i32 @tmpnam(i8* %30)
%32 = call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %32, i32** %6
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
%35 = call i32 @check_int(i32 0, i32 %34)
%36 = call i32 @range(i8* %30)
%37 = call i32 @check_int(i32 1, i32 %36)
%38 = load i8*, i8** %4
ret i32 0
}

LLVM IR (-O2):
@L_tmpnam = global i32 0
@.str = [2 x i8] c"w\00"
@.str.1 = [6 x i8] c"1231\0A\00"
@.str.2 = [3 x i8] c"1\0A\00"
@.str.3 = [5 x i8] c"441\0A\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 ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 5, i64 1, i32* %7)
%9 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i64 2, i64 1, i32* %7)
%10 = call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 4, i64 1, i32* %7)
%11 = call i32 @fclose(i32* %7)
%12 = call i32 @check_int(i32 0, i32 %11)
%13 = call i32 @range(i8* %5)
%14 = call i32 @check_int(i32 1230, i32 %13)
%15 = load i32, i32* @L_tmpnam
%16 = add nsw i32 %15, 1
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
%19 = call i32 @tmpnam(i8* %18)
%20 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @fclose(i32* %20)
%22 = call i32 @check_int(i32 0, i32 %21)
%23 = call i32 @range(i8* %18)
%24 = call i32 @check_int(i32 1, i32 %23)
ret i32 0
}