#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*/ SEEK_SET;
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int mkstemp(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int prepare_file_to_pass(void) {
  char template[] = "pass-fd-XXXXXX";
  int fd = mkstemp(template);
  if (fd < 0)
    err(1, "mkstemp() failed");
  unlink(template);
  char hello[] = "hello";
  write(fd, hello, strlen(hello));
  lseek(fd, 0, SEEK_SET);
  return fd;
}


x86 assembly (clang, -O0):
<prepare_file_to_pass>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xe91(%rip),%rax
mov    %rax,-0xf(%rbp)
mov    0xe8f(%rip),%eax
mov    %eax,-0x7(%rbp)
mov    0xe89(%rip),%ax
mov    %ax,-0x3(%rbp)
mov    0xe81(%rip),%al
mov    %al,-0x1(%rbp)
lea    -0xf(%rbp),%rdi
call   1080 <mkstemp@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b7 <prepare_file_to_pass+0x57>
mov    $0x1,%edi
lea    0xe5d(%rip),%rsi
call   1070 <err@plt>
lea    -0xf(%rbp),%rdi
call   1030 <unlink@plt>
mov    0xe5a(%rip),%eax
mov    %eax,-0x1a(%rbp)
mov    0xe54(%rip),%ax
mov    %ax,-0x16(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x1a(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x1a(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare_file_to_pass>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movabs $0x5858585858582d,%rax
mov    %rax,0xf(%rsp)
movabs $0x2d64662d73736170,%rax
66 64 2d
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1080 <mkstemp@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11a6 <prepare_file_to_pass+0x46>
lea    0xe73(%rip),%rsi
mov    $0x1,%edi
call   1070 <err@plt>
lea    0x8(%rsp),%rdi
call   1030 <unlink@plt>
movw   $0x6f,0x4(%rsp)
movl   $0x6c6c6568,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.prepare_file_to_pass.template = [15 x i8] c"pass-fd-XXXXXX\00"
@.str = [17 x i8] c"mkstemp() failed\00"
@__const.prepare_file_to_pass.hello = [6 x i8] c"hello\00"
@SEEK_SET = global i32 0
define i32 @prepare_file_to_pass() {
%1 = alloca [15 x i8]
%2 = alloca i32
%3 = alloca [6 x i8]
%4 = bitcast [15 x i8]* %1 to i8*
%5 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%6 = call i32 @mkstemp(i8* %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
%12 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%13 = call i32 @unlink(i8* %12)
%14 = bitcast [6 x i8]* %3 to i8*
%15 = load i32, i32* %2
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @write(i32 %15, i8* %16, i32 %18)
%20 = load i32, i32* %2
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @lseek(i32 %20, i32 0, i32 %21)
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@__const.prepare_file_to_pass.template = [15 x i8] c"pass-fd-XXXXXX\00"
@.str = [17 x i8] c"mkstemp() failed\00"
@__const.prepare_file_to_pass.hello = [6 x i8] c"hello\00"
@SEEK_SET = global i32 0
define i32 @prepare_file_to_pass() {
%1 = alloca [15 x i8]
%2 = alloca [6 x i8]
%3 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%4 = call i32 @mkstemp(i8* %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @err(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @unlink(i8* %3)
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %2, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @write(i32 %4, i8* %10, i32 %11)
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @lseek(i32 %4, i32 0, i32 %13)
ret i32 %4
}