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

/* Variables and functions */
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int create_file(char *func_name, int NbVal) {
  pid_t myproc;
  switch (myproc = fork()) {
  case -1:
    err(1, "fork failed");
  case 0: {
    char *arglist[] = {func_name, NULL};
    execvp(arglist[0], arglist);
    err(1, "execvp failed");
  }
  default:;
  }
  return myproc;
}


x86 assembly (clang, -O0):
<create_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
call   1050 <fork@plt>
mov    %eax,-0x10(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
sub    $0xffffffff,%eax
je     116c <create_file+0x3c>
jmp    115c <create_file+0x2c>
mov    -0x24(%rbp),%eax
test   %eax,%eax
je     117d <create_file+0x4d>
jmp    11ab <create_file+0x7b>
mov    $0x1,%edi
lea    0xe88(%rip),%rsi
call   1030 <err@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <execvp@plt>
mov    $0x1,%edi
lea    0xe66(%rip),%rsi
call   1030 <err@plt>
jmp    11b0 <create_file+0x80>
mov    -0x10(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_file>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     115d <create_file+0x2d>
cmp    $0xffffffff,%ebx
jne    1186 <create_file+0x56>
lea    0xead(%rip),%rsi
mov    $0x1,%edi
call   1030 <err@plt>
mov    %r14,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <execvp@plt>
lea    0xe90(%rip),%rsi
mov    $0x1,%edi
call   1030 <err@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [12 x i8] c"fork failed\00"
@.str.1 = [14 x i8] c"execvp failed\00"
define i32 @create_file(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [2 x i8*]
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i32 (...) @fork()
store i32 %7, i32* %5
switch i32 %7, label %19 [
i32 -1, label %8
i32 0, label %10
]
8: ; preds = %2
%9 = call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %2, %8
%11 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%12 = load i8*, i8** %3
store i8* %12, i8** %11
%13 = getelementptr inbounds i8*, i8** %11, i64 1
store i8* null, i8** %13
%14 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%15 = load i8*, i8** %14
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
%17 = call i32 @execvp(i8* %15, i8** %16)
%18 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %2, %10
br label %20
20: ; preds = %19
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
@.str = [12 x i8] c"fork failed\00"
@.str.1 = [14 x i8] c"execvp failed\00"
define i32 @create_file(i8* %0, i32 %1) {
%3 = alloca [2 x i8*]
%4 = tail call i32 (...) @fork()
switch i32 %4, label %13 [
i32 -1, label %5
i32 0, label %7
]
5: ; preds = %2
%6 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %2, %5
%8 = bitcast [2 x i8*]* %3 to i8*
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* %0, i8** %9
%10 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 1
store i8* null, i8** %10
%11 = call i32 @execvp(i8* %0, i8** %9)
%12 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %7, %2
ret i32 %4
}