#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*/ close(int);
int /*<<< orphan*/ *fdopen(int, char *);
int xmkstemp(char **, char *);
FILE *xfmkstemp(char **tmpname, char *dir) {
  int fd;
  FILE *ret;
  fd = xmkstemp(tmpname, dir);
  if (fd == -1)
    return NULL;
  if (!(ret = fdopen(fd, "w+"))) {
    close(fd);
    return NULL;
  }
  return ret;
}


x86 assembly (clang, -O0):
<xfmkstemp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <xmkstemp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1167 <xfmkstemp+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11a1 <xfmkstemp+0x71>
mov    -0x1c(%rbp),%edi
lea    0xe8f(%rip),%rsi
call   1050 <fdopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1199 <xfmkstemp+0x69>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
movq   $0x0,-0x8(%rbp)
jmp    11a1 <xfmkstemp+0x71>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xfmkstemp>:
push   %rbx
call   1030 <xmkstemp@plt>
cmp    $0xffffffff,%eax
je     1159 <xfmkstemp+0x29>
mov    %eax,%ebx
lea    0xebc(%rip),%rsi
mov    %eax,%edi
call   1050 <fdopen@plt>
test   %rax,%rax
je     1152 <xfmkstemp+0x22>
pop    %rbx
ret
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
define noalias i32* @xfmkstemp(i8** %0, i8* %1) {
%3 = tail call i32 @xmkstemp(i8** %0, i8* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = tail call i32* @fdopen(i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @close(i32 %3)
br label %10
10: ; preds = %5, %2, %8
%11 = phi i32* [ null, %8 ], [ null, %2 ], [ %6, %5 ]
ret i32* %11
}