#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           char *);
int mkstemp(char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int unlink(char *);
int open_temp_file(void) {
  char template[] = "/tmp/test-output.XXXXXX";
  int fd, err;
  do {
    if (!(fd = mkstemp(template), fd >= 0)) {
      fprintf(stderr, "%s,%d \"%s\": %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/cventus/otivm/refs/heads/master/src/"
              "ok/posix/main.c",
              97, "fd = mkstemp(template), fd >= 0", strerror(errno));
      exit(EXIT_FAILURE);
    }
  } while (0);
  do {
    if (!(err = unlink(template), err == 0)) {
      fprintf(stderr, "%s,%d \"%s\": %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/cventus/otivm/refs/heads/master/src/"
              "ok/posix/main.c",
              98, "err = unlink(template), err == 0", strerror(errno));
      exit(EXIT_FAILURE);
    }
  } while (0);
  return fd;
}


x86 assembly (clang, -O0):
<open_temp_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xea1(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe9e(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe9b(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <mkstemp@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11dc <open_temp_file+0x8c>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%r9
lea    0xe62(%rip),%rsi
lea    0xe6b(%rip),%rdx
mov    $0x61,%ecx
lea    0xeed(%rip),%r8
call   1040 <fprintf@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    11e1 <open_temp_file+0x91>
jmp    11e6 <open_temp_file+0x96>
lea    -0x20(%rbp),%rdi
call   1030 <unlink@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     1249 <open_temp_file+0xf9>
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    %rax,%r9
lea    0xdf5(%rip),%rsi
lea    0xdfe(%rip),%rdx
mov    $0x62,%ecx
lea    0xea0(%rip),%r8
call   1040 <fprintf@plt>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    124e <open_temp_file+0xfe>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_temp_file>:
push   %rbx
sub    $0x20,%rsp
movaps 0xea4(%rip),%xmm0
movaps %xmm0,(%rsp)
movabs $0x5858585858582e,%rax
mov    %rax,0x10(%rsp)
mov    %rsp,%rdi
call   1050 <mkstemp@plt>
test   %eax,%eax
js     1191 <open_temp_file+0x41>
mov    %eax,%ebx
mov    %rsp,%rdi
call   1030 <unlink@plt>
test   %eax,%eax
jne    11c6 <open_temp_file+0x76>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret
mov    0x2e48(%rip),%rax
mov    (%rax),%ebx
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe69(%rip),%rsi
lea    0xe72(%rip),%rdx
lea    0xef9(%rip),%r8
mov    %ebx,%edi
mov    $0x61,%ecx
jmp    11f9 <open_temp_file+0xa9>
mov    0x2e13(%rip),%rax
mov    (%rax),%ebx
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe34(%rip),%rsi
lea    0xe3d(%rip),%rdx
lea    0xee4(%rip),%r8
mov    %ebx,%edi
mov    $0x62,%ecx
mov    %rax,%r9
call   1040 <fprintf@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.open_temp_file.template = [24 x i8] c"/tmp/test-output.XXXXXX\00"
@stderr = global i32 0
@.str = [16 x i8] c"%s,%d \22%s\22: %s\0A\00"
@.str.1 = [142 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cventus/otivm/refs/heads/master/src/ok/posix/main.c\00"
@.str.2 = [32 x i8] c"fd = mkstemp(template), fd >= 0\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [33 x i8] c"err = unlink(template), err == 0\00"
define i32 @open_temp_file() {
%1 = alloca [24 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = bitcast [24 x i8]* %1 to i8*
br label %5
5: ; preds = %0
%6 = getelementptr inbounds [24 x i8], [24 x i8]* %1, i64 0, i64 0
%7 = call i32 @mkstemp(i8* %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp sge i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %5
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str.1, i64 0, i64 0), i32 97, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %5
br label %18
18: ; preds = %17
br label %19
19: ; preds = %18
%20 = getelementptr inbounds [24 x i8], [24 x i8]* %1, i64 0, i64 0
%21 = call i32 @unlink(i8* %20)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str.1, i64 0, i64 0), i32 98, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %19
br label %32
32: ; preds = %31
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
@__const.open_temp_file.template = [24 x i8] c"/tmp/test-output.XXXXXX\00"
@stderr = global i32 0
@.str = [16 x i8] c"%s,%d \22%s\22: %s\0A\00"
@.str.1 = [142 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cventus/otivm/refs/heads/master/src/ok/posix/main.c\00"
@.str.2 = [32 x i8] c"fd = mkstemp(template), fd >= 0\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [33 x i8] c"err = unlink(template), err == 0\00"
define i32 @open_temp_file() {
%1 = alloca [24 x i8]
%2 = getelementptr inbounds [24 x i8], [24 x i8]* %1, i64 0, i64 0
%3 = call i32 @mkstemp(i8* %2)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = call i8* @strerror(i32 %7)
%9 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str.1, i64 0, i64 0), i32 97, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = call i32 @unlink(i8* %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %22, label %15
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([142 x i8], [142 x i8]* @.str.1, i64 0, i64 0), i32 98, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %12
ret i32 %3
}