#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 */
char *basename(char *);
int execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
char *strtok(char *, char *);
int execute(char *path, char *prog) {
  int pid, i;
  char command[2 * 1024 + 1];
  int s = 0;
  char *name;
  char *argv[256];
  sprintf(command, "%s/%s", path, prog);
  name = strtok(command, " ");
  argv[0] = basename(name);
  for (i = 1; (argv[i] = strtok(NULL, " ")) != NULL; i++)
    ;
  pid = fork();
  if (pid == 0) {
    s = execv(name, argv);
    exit(0);
  }
  return pid;
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x824(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe6d(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x820(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x830(%rbp)
mov    -0x830(%rbp),%rdi
call   1030 <basename@plt>
mov    %rax,-0x1030(%rbp)
movl   $0x1,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe2f(%rip),%rsi
call   1040 <strtok@plt>
movslq -0x18(%rbp),%rcx
mov    %rax,-0x1030(%rbp,%rcx,8)
ff
cmp    $0x0,%rax
je     1205 <execute+0xa5>
jmp    11f7 <execute+0x97>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11cc <execute+0x6c>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1239 <execute+0xd9>
mov    -0x830(%rbp),%rdi
lea    -0x1030(%rbp),%rsi
call   1070 <execv@plt>
mov    %eax,-0x824(%rbp)
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %r15
push   %r14
push   %rbx
sub    $0x1010,%rsp
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xe87(%rip),%rsi
lea    0x800(%rsp),%r14
mov    %r14,%rdi
call   1050 <sprintf@plt>
lea    0xe76(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strtok@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <basename@plt>
mov    %rax,(%rsp)
lea    0x8(%rsp),%rbx
nop
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
mov    %rax,(%rbx)
add    $0x8,%rbx
test   %rax,%rax
jne    11b0 <execute+0x50>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11de <execute+0x7e>
add    $0x1010,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsp,%rsi
mov    %r14,%rdi
call   1070 <execv@plt>
xor    %edi,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [2 x i8] c" \00"
define i32 @execute(i8* %0, i8* %1) {
%3 = alloca [2049 x i8]
%4 = alloca [256 x i8*]
%5 = getelementptr inbounds [2049 x i8], [2049 x i8]* %3, i64 0, i64 0
%6 = bitcast [256 x i8*]* %4 to i8*
%7 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%8 = call i8* @strtok(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = call i8* @basename(i8* %8)
%10 = getelementptr inbounds [256 x i8*], [256 x i8*]* %4, i64 0, i64 0
store i8* %9, i8** %10
br label %11
11: ; preds = %11, %2
%12 = phi i64 [ %16, %11 ], [ 1, %2 ]
%13 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = getelementptr inbounds [256 x i8*], [256 x i8*]* %4, i64 0, i64 %12
store i8* %13, i8** %14
%15 = icmp eq i8* %13, null
%16 = add nuw i64 %12, 1
br i1 %15, label %17, label %11
17: ; preds = %11
%18 = call i32 (...) @fork()
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call i32 @execv(i8* %8, i8** %10)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %17
ret i32 %18
}