#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 /*<<< orphan*/ *fdopen(int, char *);
int mkstemp(char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
FILE *create_temp_file(char *ret_path, int ret_path_size) {
  char path[200];
  FILE *f;
  int fd;
  strcpy(path, "/tmp/m2s.XXXXXX");
  if ((fd = mkstemp(path)) == -1 || (f = fdopen(fd, "w+")) == NULL)
    return NULL;
  if (ret_path)
    strncpy(ret_path, path, ret_path_size);
  return f;
}


x86 assembly (clang, -O0):
<create_temp_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0xe0(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <strcpy@plt>
lea    -0xe0(%rbp),%rdi
call   1050 <mkstemp@plt>
mov    %eax,-0xec(%rbp)
cmp    $0xffffffff,%eax
je     11a3 <create_temp_file+0x63>
mov    -0xec(%rbp),%edi
lea    0xe83(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0xe8(%rbp)
cmp    $0x0,%rax
jne    11b0 <create_temp_file+0x70>
movq   $0x0,-0x8(%rbp)
jmp    11d9 <create_temp_file+0x99>
cmpq   $0x0,-0x10(%rbp)
je     11ce <create_temp_file+0x8e>
mov    -0x10(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0xe8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_temp_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0xd0,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0xea8(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
call   1050 <mkstemp@plt>
cmp    $0xffffffff,%eax
je     119b <create_temp_file+0x5b>
lea    0xe99(%rip),%rsi
mov    %eax,%edi
call   1060 <fdopen@plt>
test   %rax,%rax
je     119b <create_temp_file+0x5b>
mov    %rax,%rbp
test   %rbx,%rbx
je     119d <create_temp_file+0x5d>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    %r14d,%edx
call   1030 <strncpy@plt>
jmp    119d <create_temp_file+0x5d>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0xd0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/tmp/m2s.XXXXXX\00"
@.str.1 = [3 x i8] c"w+\00"
define i32* @create_temp_file(i8* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [200 x i8]
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%10 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%12 = call i32 @mkstemp(i8* %11)
store i32 %12, i32* %8
%13 = icmp eq i32 %12, -1
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load i32, i32* %8
%16 = call i32* @fdopen(i32 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %7
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %14, %2
store i32* null, i32** %3
br label %29
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%25 = load i32, i32* %5
%26 = call i32 @strncpy(i8* %23, i8* %24, i32 %25)
br label %27
27: ; preds = %22, %19
%28 = load i32*, i32** %7
store i32* %28, i32** %3
br label %29
29: ; preds = %27, %18
%30 = load i32*, i32** %3
ret i32* %30
}

LLVM IR (-O2):
@.str = [16 x i8] c"/tmp/m2s.XXXXXX\00"
@.str.1 = [3 x i8] c"w+\00"
define noalias i32* @create_temp_file(i8* %0, i32 %1) {
%3 = alloca [200 x i8]
%4 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @mkstemp(i8* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = call i32* @fdopen(i32 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = icmp eq i8* %0, null
br i1 %12, label %15, label %13
13: ; preds = %11
%14 = call i32 @strncpy(i8* %0, i8* %4, i32 %1)
br label %15
15: ; preds = %11, %13, %2, %8
%16 = phi i32* [ null, %8 ], [ null, %2 ], [ %9, %13 ], [ %9, %11 ]
ret i32* %16
}