#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 */

/* Variables and functions */
int /*<<< orphan*/ abort();
int mkstemp(char *);
char *strdup(char *);
scalar_t__ truncate(char *, int);
int /*<<< orphan*/ warn(char *);
int /*<<< orphan*/ warnx(char *, char *);
char *ecreatetmpf(int size) {
  char fname[] = ".tmp_XXXXXX";
  char *retfn;
  if (mkstemp(fname) == -1) {
    warn("mkstemp");
    abort();
  }
  if ((retfn = strdup(fname)) == NULL) {
    warn("strdup");
    abort();
  }
  if (size != 0)
    if (truncate(fname, size)) {
      warnx("truncate: %s", fname);
      abort();
    }
  return retfn;
}


x86 assembly (clang, -O0):
<ecreatetmpf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0xe8e(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xe8c(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1070 <mkstemp@plt>
cmp    $0xffffffff,%eax
jne    11a4 <ecreatetmpf+0x44>
lea    0xe74(%rip),%rdi
call   1040 <warn@plt>
mov    $0x0,%al
call   1030 <abort@plt>
lea    -0x10(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ce <ecreatetmpf+0x6e>
lea    0xe52(%rip),%rdi
call   1040 <warn@plt>
mov    $0x0,%al
call   1030 <abort@plt>
cmpl   $0x0,-0x4(%rbp)
je     120a <ecreatetmpf+0xaa>
lea    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1060 <truncate@plt>
cmp    $0x0,%rax
je     1205 <ecreatetmpf+0xa5>
lea    -0x10(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1050 <warnx@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    120a <ecreatetmpf+0xaa>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ecreatetmpf>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
movabs $0x5858585f706d742e,%rax
58 58 58
mov    %rax,0x8(%rsp)
movl   $0x585858,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1070 <mkstemp@plt>
cmp    $0xffffffff,%eax
je     11bf <ecreatetmpf+0x5f>
lea    0x8(%rsp),%rdi
call   1080 <strdup@plt>
test   %rax,%rax
je     11c8 <ecreatetmpf+0x68>
mov    %rax,%rbx
test   %ebp,%ebp
je     11b5 <ecreatetmpf+0x55>
lea    0x8(%rsp),%rdi
mov    %ebp,%esi
call   1060 <truncate@plt>
test   %rax,%rax
jne    11db <ecreatetmpf+0x7b>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe46(%rip),%rdi
jmp    11cf <ecreatetmpf+0x6f>
lea    0xe45(%rip),%rdi
call   1040 <warn@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xe39(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1050 <warnx@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@__const.ecreatetmpf.fname = [12 x i8] c".tmp_XXXXXX\00"
@.str = [8 x i8] c"mkstemp\00"
@.str.1 = [7 x i8] c"strdup\00"
@.str.2 = [13 x i8] c"truncate: %s\00"
define i8* @ecreatetmpf(i32 %0) {
%2 = alloca i32
%3 = alloca [12 x i8]
%4 = alloca i8*
store i32 %0, i32* %2
%5 = bitcast [12 x i8]* %3 to i8*
%6 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%7 = call i32 @mkstemp(i8* %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @warn(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (...) @abort()
unreachable
12: ; preds = %1
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%14 = call i8* @strdup(i8* %13)
store i8* %14, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (...) @abort()
unreachable
19: ; preds = %12
%20 = load i32, i32* %2
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%24 = load i32, i32* %2
%25 = call i64 @truncate(i8* %23, i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %22
%28 = getelementptr inbounds [12 x i8], [12 x i8]* %3, i64 0, i64 0
%29 = call i32 @warnx(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 (...) @abort()
unreachable
31: ; preds = %22
br label %32
32: ; preds = %31, %19
%33 = load i8*, i8** %4
ret i8* %33
}

LLVM IR (-O2):
@__const.ecreatetmpf.fname = [12 x i8] c".tmp_XXXXXX\00"
@.str = [8 x i8] c"mkstemp\00"
@.str.1 = [7 x i8] c"strdup\00"
@.str.2 = [13 x i8] c"truncate: %s\00"
define noalias i8* @ecreatetmpf(i32 %0) {
%2 = alloca [12 x i8]
%3 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%4 = call i32 @mkstemp(i8* %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = call i32 @warn(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @abort()
unreachable
9: ; preds = %1
%10 = call i8* @strdup(i8* %3)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i32 @warn(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (...) @abort()
unreachable
15: ; preds = %9
%16 = icmp eq i32 %0, 0
br i1 %16, label %23, label %17
17: ; preds = %15
%18 = call i64 @truncate(i8* %3, i32 %0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = call i32 @warnx(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%22 = call i32 (...) @abort()
unreachable
23: ; preds = %17, %15
ret i8* %10
}