#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 mode_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int mkstemp(char *);
int /*<<< orphan*/ perror(char *);
int umask(int);
int unlink(char *);
int raw_tempfd(char *pattern) {
  int temp_fd;
  mode_t old_mode;
  old_mode = umask(077);
  temp_fd = mkstemp(pattern);
  (void)umask(old_mode);
  if (temp_fd == -1) {
    perror("Couldn't open temporary file");
    exit(1);
  }
  if (unlink(pattern) == -1) {
    perror("Couldn't unlink temporary file");
    exit(1);
  }
  return temp_fd;
}


x86 assembly (clang, -O0):
<raw_tempfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x3f,%edi
call   1040 <umask@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <mkstemp@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <umask@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jne    119d <raw_tempfd+0x4d>
lea    0xe72(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
jne    11c5 <raw_tempfd+0x75>
lea    0xe67(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raw_tempfd>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    $0x3f,%edi
call   1040 <umask@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1050 <mkstemp@plt>
mov    %eax,%ebp
mov    %r14d,%edi
call   1040 <umask@plt>
cmp    $0xffffffff,%ebp
je     118f <raw_tempfd+0x3f>
mov    %rbx,%rdi
call   1030 <unlink@plt>
cmp    $0xffffffff,%eax
je     1198 <raw_tempfd+0x48>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe6a(%rip),%rdi
jmp    119f <raw_tempfd+0x4f>
lea    0xe7e(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"Couldn't open temporary file\00"
@.str.1 = [31 x i8] c"Couldn't unlink temporary file\00"
define i32 @raw_tempfd(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 @umask(i32 63)
store i32 %5, i32* %4
%6 = load i8*, i8** %2
%7 = call i32 @mkstemp(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %4
%9 = call i32 @umask(i32 %8)
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32 @unlink(i8* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@.str = [29 x i8] c"Couldn't open temporary file\00"
@.str.1 = [31 x i8] c"Couldn't unlink temporary file\00"
define i32 @raw_tempfd(i8* %0) {
%2 = tail call i32 @umask(i32 63)
%3 = tail call i32 @mkstemp(i8* %0)
%4 = tail call i32 @umask(i32 %2)
%5 = icmp eq i32 %3, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = tail call i32 @unlink(i8* %0)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %9
ret i32 %3
}