#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 O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ memcpy(char *, char *, int);
char *mkdtemp(char *);
int open(char *, int);
int strlen(char *);
char *SetupFiles(char *tempDir, char *hashFile, int *hashFD) {
  char *tempName = mkdtemp(tempDir);
  int tempSize = strlen(tempName);
  int hashSize = strlen(hashFile);
  char hashTemp[tempSize + hashSize + 2];
  memcpy(hashTemp, tempName, tempSize);
  hashTemp[tempSize] = '/';
  memcpy(hashTemp + tempSize + 1, hashFile, hashSize);
  hashTemp[tempSize + hashSize + 1] = '\0';
  *hashFD = open(hashTemp, O_CREAT | O_WRONLY | O_TRUNC);
  return tempName;
}


x86 assembly (clang, -O0):
<SetupFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <mkdtemp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%eax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x2(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x40(%rbp),%rdi
movslq -0x24(%rbp),%rax
movb   $0x2f,(%rdi,%rax,1)
movslq -0x24(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,(%rdi,%rax,1)
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    0x2dcc(%rip),%rax
or     (%rax),%esi
mov    0x2deb(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetupFiles>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,-0x38(%rbp)
mov    %rsi,%r15
call   1050 <mkdtemp@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
lea    (%r14,%r13,1),%eax
mov    %eax,-0x2c(%rbp)
lea    (%r14,%r13,1),%eax
add    $0x2,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
movslq %r14d,%rax
movb   $0x2f,(%rax,%rbx,1)
lea    (%rax,%rbx,1),%rdi
add    $0x1,%rdi
mov    %r15,%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
mov    0x2e34(%rip),%rax
mov    0x2dfd(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
movslq -0x2c(%rbp),%rax
movb   $0x0,0x1(%rax,%rbx,1)
mov    0x2e11(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    -0x38(%rbp),%rcx
mov    %eax,(%rcx)
mov    %r12,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
define i8* @SetupFiles(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%12 = load i8*, i8** %4
%13 = call i8* @mkdtemp(i8* %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %8
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %9
%18 = load i32, i32* %8
%19 = load i32, i32* %9
%20 = add nsw i32 %18, %19
%21 = add nsw i32 %20, 2
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %10
%24 = alloca i8, i64 %22
store i64 %22, i64* %11
%25 = load i8*, i8** %7
%26 = load i32, i32* %8
%27 = call i32 @memcpy(i8* %24, i8* %25, i32 %26)
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %24, i64 %29
store i8 47, i8* %30
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %24, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 1
%35 = load i8*, i8** %5
%36 = load i32, i32* %9
%37 = call i32 @memcpy(i8* %34, i8* %35, i32 %36)
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = add nsw i32 %38, %39
%41 = add nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %24, i64 %42
store i8 0, i8* %43
%44 = load i32, i32* @O_CREAT
%45 = load i32, i32* @O_WRONLY
%46 = or i32 %44, %45
%47 = load i32, i32* @O_TRUNC
%48 = or i32 %46, %47
%49 = call i32 @open(i8* %24, i32 %48)
%50 = load i32*, i32** %6
store i32 %49, i32* %50
%51 = load i8*, i8** %7
%52 = load i8*, i8** %10
ret i8* %51
}

LLVM IR (-O2):
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
define i8* @SetupFiles(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = tail call i8* @mkdtemp(i8* %0)
%5 = tail call i32 @strlen(i8* %4)
%6 = tail call i32 @strlen(i8* %1)
%7 = add nsw i32 %6, %5
%8 = add nsw i32 %7, 2
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = call i32 @memcpy(i8* %10, i8* %4, i32 %5)
%12 = sext i32 %5 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
store i8 47, i8* %13
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i32 @memcpy(i8* %14, i8* %1, i32 %6)
%16 = add nsw i32 %7, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %10, i64 %17
store i8 0, i8* %18
%19 = load i32, i32* @O_CREAT
%20 = load i32, i32* @O_WRONLY
%21 = or i32 %20, %19
%22 = load i32, i32* @O_TRUNC
%23 = or i32 %21, %22
%24 = call i32 @open(i8* %10, i32 %23)
store i32 %24, i32* %2
ret i8* %4
}