#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*/ err(int, char *);
scalar_t__ ftruncate(int, int);
int mkstemp(char *);
int /*<<< orphan*/ remove(char *);
int getafile(void) {
  int fd;
  char temp[] = "/tmp/dup2XXXXXXXXX";
  if ((fd = mkstemp(temp)) < 0)
    err(1, "mkstemp");
  remove(temp);
  if (ftruncate(fd, 1024) != 0)
    err(1, "ftruncate");
  return (fd);
}


x86 assembly (clang, -O0):
<getafile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xeb1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xeab(%rip),%ax
mov    %ax,-0x10(%rbp)
mov    0xea3(%rip),%al
mov    %al,-0xe(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <mkstemp@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jge    1198 <getafile+0x58>
mov    $0x1,%edi
lea    0xe80(%rip),%rsi
call   1050 <err@plt>
lea    -0x20(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x4(%rbp),%edi
mov    $0x400,%esi
call   1040 <ftruncate@plt>
cmp    $0x0,%rax
je     11c9 <getafile+0x89>
mov    $0x1,%edi
lea    0xe57(%rip),%rsi
call   1050 <err@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getafile>:
push   %rbx
sub    $0x20,%rsp
movaps 0xeb4(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x585858,0xf(%rsp)
mov    %rsp,%rdi
call   1060 <mkstemp@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1177 <getafile+0x37>
lea    0xea6(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    %rsp,%rdi
call   1030 <remove@plt>
mov    %ebx,%edi
mov    $0x400,%esi
call   1040 <ftruncate@plt>
test   %rax,%rax
je     11a1 <getafile+0x61>
lea    0xe84(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.getafile.temp = [19 x i8] c"/tmp/dup2XXXXXXXXX\00"
@.str = [8 x i8] c"mkstemp\00"
@.str.1 = [10 x i8] c"ftruncate\00"
define i32 @getafile() {
%1 = alloca i32
%2 = alloca [19 x i8]
%3 = bitcast [19 x i8]* %2 to i8*
%4 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%5 = call i32 @mkstemp(i8* %4)
store i32 %5, i32* %1
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = getelementptr inbounds [19 x i8], [19 x i8]* %2, i64 0, i64 0
%11 = call i32 @remove(i8* %10)
%12 = load i32, i32* %1
%13 = call i64 @ftruncate(i32 %12, i32 1024)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
@__const.getafile.temp = [19 x i8] c"/tmp/dup2XXXXXXXXX\00"
@.str = [8 x i8] c"mkstemp\00"
@.str.1 = [10 x i8] c"ftruncate\00"
define i32 @getafile() {
%1 = alloca [19 x i8]
%2 = getelementptr inbounds [19 x i8], [19 x i8]* %1, i64 0, i64 0
%3 = call i32 @mkstemp(i8* %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 @err(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = call i32 @remove(i8* %2)
%9 = call i64 @ftruncate(i32 %3, i32 1024)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
ret i32 %3
}