#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*/ errno;
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ pm_error(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ pm_make_tmpfile_fd(int *, char const **const);
int /*<<< orphan*/ pm_strfree(char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char const *);
void pm_make_tmpfile(FILE **const filePP, const char **const filenameP) {
  int fd;
  pm_make_tmpfile_fd(&fd, filenameP);
  *filePP = fdopen(fd, "w+b");
  if (*filePP == NULL) {
    close(fd);
    unlink(*filenameP);
    pm_strfree(*filenameP);
    pm_error("Unable to create temporary file.  "
             "fdopen() failed with errno %d (%s)",
             errno, strerror(errno));
  }
}


x86 assembly (clang, -O0):
<pm_make_tmpfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdi
call   1040 <pm_make_tmpfile_fd@plt>
mov    -0x14(%rbp),%edi
lea    0xe69(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ff <pm_make_tmpfile+0x8f>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <unlink@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <pm_strfree@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
lea    0xe0a(%rip),%rdi
call   1090 <pm_error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pm_make_tmpfile>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x4(%rsp),%rdi
call   1040 <pm_make_tmpfile_fd@plt>
mov    0x4(%rsp),%edi
lea    0xe71(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,(%rbx)
test   %rax,%rax
jne    11d5 <pm_make_tmpfile+0x65>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
mov    (%r14),%rdi
call   1030 <unlink@plt>
mov    (%r14),%rdi
call   1060 <pm_strfree@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1080 <strerror@plt>
lea    0xe38(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1090 <pm_error@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"w+b\00"
@.str.1 = [69 x i8] c"Unable to create temporary file. fdopen() failed with errno %d (%s)\00"
@errno = global i32 0
define void @pm_make_tmpfile(i32** %0, i8** %1) {
%3 = alloca i32**
%4 = alloca i8**
%5 = alloca i32
store i32** %0, i32*** %3
store i8** %1, i8*** %4
%6 = load i8**, i8*** %4
%7 = call i32 @pm_make_tmpfile_fd(i32* %5, i8** %6)
%8 = load i32, i32* %5
%9 = call i32* @fdopen(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = load i32**, i32*** %3
store i32* %9, i32** %10
%11 = load i32**, i32*** %3
%12 = load i32*, i32** %11
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %27
14: ; preds = %2
%15 = load i32, i32* %5
%16 = call i32 @close(i32 %15)
%17 = load i8**, i8*** %4
%18 = load i8*, i8** %17
%19 = call i32 @unlink(i8* %18)
%20 = load i8**, i8*** %4
%21 = load i8*, i8** %20
%22 = call i32 @pm_strfree(i8* %21)
%23 = load i32, i32* @errno
%24 = load i32, i32* @errno
%25 = call i32 @strerror(i32 %24)
%26 = call i32 @pm_error(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %25)
br label %27
27: ; preds = %14, %2
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"w+b\00"
@.str.1 = [69 x i8] c"Unable to create temporary file. fdopen() failed with errno %d (%s)\00"
@errno = global i32 0
define void @pm_make_tmpfile(i32** nocapture writeonly %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @pm_make_tmpfile_fd(i32* %3, i8** %1)
%6 = load i32, i32* %3
%7 = call i32* @fdopen(i32 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %0
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = load i32, i32* %3
%11 = call i32 @close(i32 %10)
%12 = load i8*, i8** %1
%13 = call i32 @unlink(i8* %12)
%14 = load i8*, i8** %1
%15 = call i32 @pm_strfree(i8* %14)
%16 = load i32, i32* @errno
%17 = call i32 @strerror(i32 %16)
%18 = call i32 @pm_error(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
br label %19
19: ; preds = %9, %2
ret void
}