#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*/ _exit(int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  pid_t pid;
  pid = fork();
  if (pid == -1) {
    exit(1);
  } else if (pid == 0) {
    int i;
    char *cmd = argv[1];
    char *args[argc - 1];
    for (i = 1; i < argc; i++) {
      args[i - 1] = argv[i];
    }
    args[argc - 1] = NULL;
    printf("%s: ", cmd);
    for (i = 0; i < argc - 1; i++) {
      printf("%s ", args[i]);
    }
    printf("\n");
    execvp(cmd, args);
    printf("Something bad happened!\n");
    _exit(1);
  } else {
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1184 <main+0x34>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    129c <main+0x14c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
lea    0xf(,%rax,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1202 <main+0xb2>
mov    -0x38(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x18(%rbp),%rdx
mov    (%rcx,%rdx,8),%rdx
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11cb <main+0x7b>
mov    -0x38(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x20(%rbp),%rsi
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1269 <main+0x119>
mov    -0x38(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1230 <main+0xe0>
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdi
call   1050 <execvp@plt>
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r12d
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11b2 <main+0x32>
cmp    $0xffffffff,%eax
jne    123a <main+0xba>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x8(%r15),%rcx
lea    -0x1(%r12),%r14d
mov    %rsp,%r13
lea    0xf(,%r14,8),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
cmp    $0x1,%r12d
mov    %rcx,%r12
jle    1241 <main+0xc1>
add    $0x8,%r15
lea    0x0(,%r14,8),%rdx
mov    %r13,%rdi
mov    %r15,%rsi
call   1070 <memcpy@plt>
movq   $0x0,0x0(%r13,%r14,8)
lea    0xe00(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf4(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13,%rbx,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1220 <main+0xa0>
jmp    125e <main+0xde>
xor    %edi,%edi
call   1090 <exit@plt>
movslq %r14d,%rax
movq   $0x0,0x0(%r13,%rax,8)
lea    0xdac(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <execvp@plt>
lea    0xd8f(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s: \00"
@.str.1 = [4 x i8] c"%s \00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [25 x i8] c"Something bad happened!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 (...) @fork()
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %72
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %8
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
store i8* %26, i8** %9
%27 = alloca i8*, i64 %25
store i64 %25, i64* %10
store i32 1, i32* %7
br label %28
28: ; preds = %42, %19
%29 = load i32, i32* %7
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %45
32: ; preds = %28
%33 = load i8**, i8*** %5
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = load i32, i32* %7
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %27, i64 %40
store i8* %37, i8** %41
br label %42
42: ; preds = %32
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %28
45: ; preds = %28
%46 = load i32, i32* %4
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %27, i64 %48
store i8* null, i8** %49
%50 = load i8*, i8** %8
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %50)
store i32 0, i32* %7
br label %52
52: ; preds = %63, %45
%53 = load i32, i32* %7
%54 = load i32, i32* %4
%55 = sub nsw i32 %54, 1
%56 = icmp slt i32 %53, %55
br i1 %56, label %57, label %66
57: ; preds = %52
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %27, i64 %59
%61 = load i8*, i8** %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %57
%64 = load i32, i32* %7
%65 = add nsw i32 %64, 1
store i32 %65, i32* %7
br label %52
66: ; preds = %52
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%68 = load i8*, i8** %8
%69 = call i32 @execvp(i8* %68, i8** %27)
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%71 = call i32 @_exit(i32 1)
unreachable
72: ; preds = %16
%73 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s: \00"
@.str.1 = [4 x i8] c"%s \00"
@str = [24 x i8] c"Something bad happened!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %36 [
i32 -1, label %4
i32 0, label %6
]
4: ; preds = %2
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %2
%7 = getelementptr i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = add i32 %0, -1
%10 = zext i32 %9 to i64
%11 = alloca i8*, i64 %10
%12 = icmp sgt i32 %0, 1
br i1 %12, label %17, label %13
13: ; preds = %6
%14 = sext i32 %9 to i64
%15 = getelementptr inbounds i8*, i8** %11, i64 %14
store i8* null, i8** %15
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %31
17: ; preds = %6
%18 = bitcast i8** %11 to i8*
%19 = bitcast i8** %7 to i8*
%20 = shl nuw nsw i64 %10, 3
%21 = zext i32 %9 to i64
%22 = getelementptr inbounds i8*, i8** %11, i64 %21
store i8* null, i8** %22
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %24
24: ; preds = %17, %24
%25 = phi i64 [ 0, %17 ], [ %29, %24 ]
%26 = getelementptr inbounds i8*, i8** %11, i64 %25
%27 = load i8*, i8** %26
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = add nuw nsw i64 %25, 1
%30 = icmp eq i64 %29, %10
br i1 %30, label %31, label %24
31: ; preds = %24, %13
%32 = tail call i32 @putchar(i32 10)
%33 = call i32 @execvp(i8* %8, i8** %11)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%35 = call i32 @_exit(i32 1)
unreachable
36: ; preds = %2
%37 = tail call i32 @exit(i32 0)
unreachable
}