#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 /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *);
char *strsep(char **, char *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int run_exec(char *cmd) {
  int f;
  int *i;
  f = fork();
  if (!f) {
    char *cmdname;
    cmd = strsep(&cmd, "\n");
    cmdname = strsep(&cmd, " ");
    char *args[256];
    args[0] = cmdname;
    int x;
    x = 1;
    while (cmd) {
      char *arg = strsep(&cmd, " ");
      args[x] = arg;
      x++;
    }
    args[x] = NULL;
    execvp(cmdname, args);
    printf("Done execing\n");
    exit(0);
  } else {
    int status;
    waitpid(f, &status, 0);
  }
}


x86 assembly (clang, -O0):
<run_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1242 <run_exec+0xe2>
lea    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x830(%rbp)
movl   $0x1,-0x834(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     120c <run_exec+0xac>
lea    -0x10(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   1040 <strsep@plt>
mov    %rax,-0x840(%rbp)
mov    -0x840(%rbp),%rcx
movslq -0x834(%rbp),%rax
mov    %rcx,-0x830(%rbp,%rax,8)
ff
mov    -0x834(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x834(%rbp)
jmp    11c0 <run_exec+0x60>
movslq -0x834(%rbp),%rax
movq   $0x0,-0x830(%rbp,%rax,8)
mov    -0x28(%rbp),%rdi
lea    -0x830(%rbp),%rsi
call   1060 <execvp@plt>
lea    0xdcc(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x844(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_exec>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rdi,0x8(%rsp)
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     119b <run_exec+0x3b>
lea    0x10(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe5e(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strsep@plt>
mov    %rax,0x8(%rsp)
lea    0xe47(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strsep@plt>
mov    %rax,%r14
mov    %rax,0x10(%rsp)
mov    $0x1,%eax
cmpq   $0x0,0x8(%rsp)
je     120e <run_exec+0xae>
mov    $0x1,%ebx
lea    0xe1e(%rip),%r15
lea    0x8(%rsp),%r12
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strsep@plt>
mov    %rax,0x10(%rsp,%rbx,8)
add    $0x1,%rbx
cmpq   $0x0,0x8(%rsp)
jne    11f0 <run_exec+0x90>
mov    %ebx,%eax
movq   $0x0,0x10(%rsp,%rax,8)
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1060 <execvp@plt>
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [14 x i8] c"Done execing\0A\00"
define i32 @run_exec(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca [256 x i8*]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
%11 = call i32 (...) @fork()
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %39, label %14
14: ; preds = %1
%15 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %3
%16 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = getelementptr inbounds [256 x i8*], [256 x i8*]* %7, i64 0, i64 0
store i8* %17, i8** %18
store i32 1, i32* %8
br label %19
19: ; preds = %22, %14
%20 = load i8*, i8** %3
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %23, i8** %9
%24 = load i8*, i8** %9
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [256 x i8*], [256 x i8*]* %7, i64 0, i64 %26
store i8* %24, i8** %27
%28 = load i32, i32* %8
%29 = add nsw i32 %28, 1
store i32 %29, i32* %8
br label %19
30: ; preds = %19
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [256 x i8*], [256 x i8*]* %7, i64 0, i64 %32
store i8* null, i8** %33
%34 = load i8*, i8** %6
%35 = getelementptr inbounds [256 x i8*], [256 x i8*]* %7, i64 0, i64 0
%36 = call i32 @execvp(i8* %34, i8** %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %1
%40 = load i32, i32* %4
%41 = call i32 @waitpid(i32 %40, i32* %10, i32 0)
br label %42
42: ; preds = %39
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@.str.1 = [2 x i8] c" \00"
@str = [13 x i8] c"Done execing\00"
define i32 @run_exec(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8*]
%4 = alloca i32
store i8* %0, i8** %2
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %29
7: ; preds = %1
%8 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %2
%9 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = bitcast [256 x i8*]* %3 to i8*
%11 = getelementptr inbounds [256 x i8*], [256 x i8*]* %3, i64 0, i64 0
store i8* %9, i8** %11
%12 = load i8*, i8** %2
%13 = icmp eq i8* %12, null
br i1 %13, label %23, label %14
14: ; preds = %7, %14
%15 = phi i64 [ %18, %14 ], [ 1, %7 ]
%16 = call i8* @strsep(i8** %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = getelementptr inbounds [256 x i8*], [256 x i8*]* %3, i64 0, i64 %15
store i8* %16, i8** %17
%18 = add nuw i64 %15, 1
%19 = load i8*, i8** %2
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %14
21: ; preds = %14
%22 = and i64 %18, 4294967295
br label %23
23: ; preds = %21, %7
%24 = phi i64 [ 1, %7 ], [ %22, %21 ]
%25 = getelementptr inbounds [256 x i8*], [256 x i8*]* %3, i64 0, i64 %24
store i8* null, i8** %25
%26 = call i32 @execvp(i8* %9, i8** %11)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %1
%30 = bitcast i32* %4 to i8*
%31 = call i32 @waitpid(i32 %5, i32* %4, i32 0)
ret i32 undef
}