#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*/ FILE;

/* Variables and functions */
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int /*<<< orphan*/ fchmod(int, int);
int /*<<< orphan*/ *fdopen(int, char *);
int mkstemp(char *);
FILE *mktempmode(char *tmp, int mode) {
  int fd = mkstemp(tmp);
  if (fd < 0)
    return (NULL);
  fchmod(fd, mode & (S_IRWXU | S_IRWXG | S_IRWXO));
  return (fdopen(fd, "wb"));
}


x86 assembly (clang, -O0):
<mktempmode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <mkstemp@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1162 <mktempmode+0x32>
movq   $0x0,-0x8(%rbp)
jmp    119d <mktempmode+0x6d>
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    0x2e60(%rip),%rcx
or     (%rcx),%eax
mov    0x2e6f(%rip),%rcx
or     (%rcx),%eax
and    %eax,%esi
call   1050 <fchmod@plt>
mov    -0x18(%rbp),%edi
lea    0xe6c(%rip),%rsi
call   1040 <fdopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mktempmode>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
call   1030 <mkstemp@plt>
test   %eax,%eax
js     1178 <mktempmode+0x48>
mov    %eax,%ebx
mov    0x2e99(%rip),%rax
mov    0x2e8a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e97(%rip),%rax
or     (%rax),%esi
and    %ebp,%esi
mov    %ebx,%edi
call   1050 <fchmod@plt>
lea    0xe95(%rip),%rsi
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fdopen@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str = [3 x i8] c"wb\00"
define i32* @mktempmode(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = call i32 @mkstemp(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32* null, i32** %3
br label %24
12: ; preds = %2
%13 = load i32, i32* %6
%14 = load i32, i32* %5
%15 = load i32, i32* @S_IRWXU
%16 = load i32, i32* @S_IRWXG
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IRWXO
%19 = or i32 %17, %18
%20 = and i32 %14, %19
%21 = call i32 @fchmod(i32 %13, i32 %20)
%22 = load i32, i32* %6
%23 = call i32* @fdopen(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %3
br label %24
24: ; preds = %12, %11
%25 = load i32*, i32** %3
ret i32* %25
}

LLVM IR (-O2):
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str = [3 x i8] c"wb\00"
define noalias i32* @mktempmode(i8* %0, i32 %1) {
%3 = tail call i32 @mkstemp(i8* %0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %2
%6 = load i32, i32* @S_IRWXU
%7 = load i32, i32* @S_IRWXG
%8 = or i32 %7, %6
%9 = load i32, i32* @S_IRWXO
%10 = or i32 %8, %9
%11 = and i32 %10, %1
%12 = tail call i32 @fchmod(i32 %3, i32 %11)
%13 = tail call i32* @fdopen(i32 %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %2, %5
%15 = phi i32* [ %13, %5 ], [ null, %2 ]
ret i32* %15
}