#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 /*<<< orphan*/ sigset_t;
typedef int /*<<< orphan*/ path;

/* Variables and functions */
int MAXPATHLEN;
int /*<<< orphan*/ SIG_BLOCK;
int /*<<< orphan*/ SIG_SETMASK;
char *getenv(char *);
int mkstemp(char *);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int /*<<< orphan*/ sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ strconcat(char *, int, char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
int tmp() {
  sigset_t set, oset;
  int fd;
  char *envtmp;
  char path[MAXPATHLEN];
  envtmp = getenv("TMPDIR");
  if (!envtmp)
    envtmp = "/tmp";
  strconcat(path, sizeof(path), envtmp, "/bt.XXXXXX", NULL);
  (void)sigfillset(&set);
  (void)sigprocmask(SIG_BLOCK, &set, &oset);
  if ((fd = mkstemp(path)) != -1)
    (void)unlink(path);
  (void)sigprocmask(SIG_SETMASK, &oset, NULL);
  return (fd);
}


x86 assembly (clang, -O0):
<tmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    0xe61(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11be <tmp+0x5e>
lea    0xe4d(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
lea    0xe39(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <strconcat@plt>
lea    -0x4(%rbp),%rdi
call   1070 <sigfillset@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    -0x4(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <sigprocmask@plt>
mov    -0x30(%rbp),%rdi
call   1080 <mkstemp@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
je     121a <tmp+0xba>
mov    -0x30(%rbp),%rdi
call   1050 <unlink@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <sigprocmask@plt>
mov    -0xc(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tmp>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsp,%r15
mov    0x2e6c(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe6e(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe66(%rip),%rdx
cmovne %rax,%rdx
lea    0xe60(%rip),%rcx
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %r8d,%r8d
call   1060 <strconcat@plt>
lea    -0x20(%rbp),%r14
mov    %r14,%rdi
call   1070 <sigfillset@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rdx
mov    %r14,%rsi
call   1040 <sigprocmask@plt>
mov    %rbx,%rdi
call   1080 <mkstemp@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
je     11f3 <tmp+0x93>
mov    %rbx,%rdi
call   1050 <unlink@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1040 <sigprocmask@plt>
mov    %r15,%rsp
mov    %r14d,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [11 x i8] c"/bt.XXXXXX\00"
@SIG_BLOCK = global i32 0
@SIG_SETMASK = global i32 0
define i32 @tmp() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = load i32, i32* @MAXPATHLEN
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %5
%10 = alloca i8, i64 %8
store i64 %8, i64* %6
%11 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %4
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %15, label %14
14: ; preds = %0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %15
15: ; preds = %14, %0
%16 = trunc i64 %8 to i32
%17 = load i8*, i8** %4
%18 = call i32 @strconcat(i8* %10, i32 %16, i8* %17, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32* null)
%19 = call i32 @sigfillset(i32* %1)
%20 = load i32, i32* @SIG_BLOCK
%21 = call i32 @sigprocmask(i32 %20, i32* %1, i32* %2)
%22 = call i32 @mkstemp(i8* %10)
store i32 %22, i32* %3
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %15
%25 = call i32 @unlink(i8* %10)
br label %26
26: ; preds = %24, %15
%27 = load i32, i32* @SIG_SETMASK
%28 = call i32 @sigprocmask(i32 %27, i32* %2, i32* null)
%29 = load i32, i32* %3
%30 = load i8*, i8** %5
ret i32 %29
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"/tmp\00"
@.str.2 = [11 x i8] c"/bt.XXXXXX\00"
@SIG_BLOCK = global i32 0
@SIG_SETMASK = global i32 0
define i32 @tmp() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @MAXPATHLEN
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
%11 = select i1 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %9
%12 = call i32 @strconcat(i8* %8, i32 %5, i8* %11, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32* null)
%13 = call i32 @sigfillset(i32* %1)
%14 = load i32, i32* @SIG_BLOCK
%15 = call i32 @sigprocmask(i32 %14, i32* %1, i32* %2)
%16 = call i32 @mkstemp(i8* %8)
%17 = icmp eq i32 %16, -1
br i1 %17, label %20, label %18
18: ; preds = %0
%19 = call i32 @unlink(i8* %8)
br label %20
20: ; preds = %18, %0
%21 = load i32, i32* @SIG_SETMASK
%22 = call i32 @sigprocmask(i32 %21, i32* %2, i32* null)
ret i32 %16
}