#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 errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int handle_ptr(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *tmpfile();
FILE *tmpfile_test(void) {
  FILE *ret;
  int save_errno;
  int passed;
  printf("tmpfile():\n");
  fflush(NULL);
  passed = handle_ptr(ret = tmpfile());
  save_errno = errno;
  switch (passed) {
  case -1:
  case 0:
    printf("\tret = 0x%p\n", ret);
    printf("\tSucceeded Phase 1\n");
    fflush(NULL);
    break;
  case -2:
    printf("\tFailed Phase 1: returned undefined value! "
           "ret = 0x%p\n",
           ret);
    fflush(NULL);
    break;
  default:
    printf("Internal syscalltester error: passed = %d\n", passed);
    fflush(NULL);
    break;
  }
  errno = save_errno;
  return ret;
}


x86 assembly (clang, -O0):
<tmpfile_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
mov    %al,-0x15(%rbp)
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,%edi
call   1060 <fflush@plt>
mov    -0x15(%rbp),%al
call   1040 <tmpfile@plt>
mov    %rax,%rdi
mov    %rdi,-0x8(%rbp)
call   1050 <handle_ptr@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0xfffffffe,%eax
je     11df <tmpfile_test+0x9f>
jmp    119d <tmpfile_test+0x5d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
sub    $0x1,%eax
ja     11ff <tmpfile_test+0xbf>
jmp    11b1 <tmpfile_test+0x71>
mov    -0x8(%rbp),%rsi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
jmp    1219 <tmpfile_test+0xd9>
mov    -0x8(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
jmp    1219 <tmpfile_test+0xd9>
mov    -0x10(%rbp),%esi
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <fflush@plt>
mov    -0xc(%rbp),%ecx
mov    0x2dbd(%rip),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmpfile_test>:
push   %rbp
push   %r14
push   %rbx
lea    0xf14(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
xor    %eax,%eax
call   1050 <tmpfile@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <handle_ptr@plt>
mov    0x2e60(%rip),%r14
mov    (%r14),%ebp
lea    0x1(%rax),%ecx
cmp    $0x2,%ecx
jae    11aa <tmpfile_test+0x5a>
lea    0xe6e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xed7(%rip),%rdi
call   1030 <puts@plt>
jmp    11d2 <tmpfile_test+0x82>
cmp    $0xfffffffe,%eax
jne    11c2 <tmpfile_test+0x72>
lea    0xe57(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d2 <tmpfile_test+0x82>
lea    0xe7b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <fflush@plt>
mov    %ebp,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"tmpfile():\0A\00"
@errno = global i32 0
@.str.1 = [13 x i8] c"\09ret = 0x%p\0A\00"
@.str.2 = [20 x i8] c"\09Succeeded Phase 1\0A\00"
@.str.3 = [55 x i8] c"\09Failed Phase 1: returned undefined value! ret = 0x%p\0A\00"
@.str.4 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
define i32* @tmpfile_test() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @fflush(i32* null)
%6 = call i32* (...) @tmpfile()
store i32* %6, i32** %1
%7 = call i32 @handle_ptr(i32* %6)
store i32 %7, i32* %3
%8 = load i32, i32* @errno
store i32 %8, i32* %2
%9 = load i32, i32* %3
switch i32 %9, label %19 [
i32 -1, label %10
i32 0, label %10
i32 -2, label %15
]
10: ; preds = %0, %0
%11 = load i32*, i32** %1
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @fflush(i32* null)
br label %23
15: ; preds = %0
%16 = load i32*, i32** %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32* %16)
%18 = call i32 @fflush(i32* null)
br label %23
19: ; preds = %0
%20 = load i32, i32* %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = call i32 @fflush(i32* null)
br label %23
23: ; preds = %19, %15, %10
%24 = load i32, i32* %2
store i32 %24, i32* @errno
%25 = load i32*, i32** %1
ret i32* %25
}

LLVM IR (-O2):
@errno = global i32 0
@.str.1 = [13 x i8] c"\09ret = 0x%p\0A\00"
@.str.3 = [55 x i8] c"\09Failed Phase 1: returned undefined value! ret = 0x%p\0A\00"
@.str.4 = [43 x i8] c"Internal syscalltester error: passed = %d\0A\00"
@str = [11 x i8] c"tmpfile():\00"
@str.5 = [19 x i8] c"\09Succeeded Phase 1\00"
define i32* @tmpfile_test() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @fflush(i32* null)
%3 = tail call i32* (...) @tmpfile()
%4 = tail call i32 @handle_ptr(i32* %3)
%5 = load i32, i32* @errno
switch i32 %4, label %11 [
i32 -1, label %6
i32 0, label %6
i32 -2, label %9
]
6: ; preds = %0, %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
br label %13
9: ; preds = %0
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32* %3)
br label %13
11: ; preds = %0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %4)
br label %13
13: ; preds = %11, %9, %6
%14 = tail call i32 @fflush(i32* null)
store i32 %5, i32* @errno
ret i32* %3
}