#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;
typedef int /*<<< orphan*/ dir;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ temp_file_name(int, char *, char *);
FILE *open_temp_file(int type) {
  char file[1024];
  char dir[1024];
  FILE *fp;
  memset(&dir, 0, sizeof(dir));
  memset(&file, 0, sizeof(file));
  temp_file_name(type, dir, file);
  if ((fp = fopen(file, "wb+")) == NULL) {
    perror(file);
    return ((FILE *)NULL);
  }
  return (fp);
}


x86 assembly (clang, -O0):
<open_temp_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x810(%rbp),%rsi
lea    -0x410(%rbp),%rdx
call   1040 <temp_file_name@plt>
lea    -0x410(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x818(%rbp)
cmp    $0x0,%rax
jne    11c7 <open_temp_file+0x87>
lea    -0x410(%rbp),%rdi
call   1060 <perror@plt>
movq   $0x0,-0x8(%rbp)
jmp    11d2 <open_temp_file+0x92>
mov    -0x818(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_temp_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %edi,%ebp
lea    0x400(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <temp_file_name@plt>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a9 <open_temp_file+0x69>
mov    %rbx,%rax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rsp,%rdi
call   1060 <perror@plt>
jmp    119a <open_temp_file+0x5a>

LLVM IR (-O0):
@.str = [4 x i8] c"wb+\00"
define i32* @open_temp_file(i32 %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32*
store i32 %0, i32* %3
%7 = bitcast [1024 x i8]* %5 to i8**
%8 = call i32 @memset(i8** %7, i32 0, i32 1024)
%9 = bitcast [1024 x i8]* %4 to i8**
%10 = call i32 @memset(i8** %9, i32 0, i32 1024)
%11 = load i32, i32* %3
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%14 = call i32 @temp_file_name(i32 %11, i8* %12, i8* %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %1
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%20 = call i32 @perror(i8* %19)
store i32* null, i32** %2
br label %23
21: ; preds = %1
%22 = load i32*, i32** %6
store i32* %22, i32** %2
br label %23
23: ; preds = %21, %18
%24 = load i32*, i32** %2
ret i32* %24
}

LLVM IR (-O2):
@.str = [4 x i8] c"wb+\00"
define noalias i32* @open_temp_file(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast [1024 x i8]* %3 to i8**
%7 = call i32 @memset(i8** %6, i32 0, i32 1024)
%8 = bitcast [1024 x i8]* %2 to i8**
%9 = call i32 @memset(i8** %8, i32 0, i32 1024)
%10 = call i32 @temp_file_name(i32 %0, i8* %5, i8* %4)
%11 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @perror(i8* %4)
br label %15
15: ; preds = %1, %13
ret i32* %11
}