#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*/ _exit(int);
int /*<<< orphan*/ execv(char const *, char **);
int fork();
int /*<<< orphan*/ printf(char *, ...);
char **put_end_params(char const **, int);
int launch_command(const char **argv, int argc) {
  int pid;
  char **args;
  if (argc < 1 || !argv[0])
    return -1;
  args = put_end_params(argv, argc);
  if ((pid = fork()) == 0) {
    execv(argv[0], args);
    printf("MIG-CTRL> \n Child has ended execution \n");
    _exit(2);
  } else {
    printf("MIG-CTRL> Command launched with pid %d \n", pid);
    return pid;
  }
}


x86 assembly (clang, -O0):
<launch_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jl     1177 <launch_command+0x27>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1183 <launch_command+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e5 <launch_command+0x95>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <put_end_params@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    11ce <launch_command+0x7e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <execv@plt>
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x2,%edi
call   1030 <_exit@plt>
mov    -0x18(%rbp),%esi
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launch_command>:
push   %r15
push   %r14
push   %rbx
mov    $0xffffffff,%ebx
test   %esi,%esi
jle    119f <launch_command+0x3f>
mov    %rdi,%r14
cmpq   $0x0,(%rdi)
je     119f <launch_command+0x3f>
mov    %r14,%rdi
call   1060 <put_end_params@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11a7 <launch_command+0x47>
mov    %eax,%ebx
lea    0xe6a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    (%r14),%rdi
mov    %r15,%rsi
call   1070 <execv@plt>
lea    0xe70(%rip),%rdi
call   1040 <puts@plt>
mov    $0x2,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"MIG-CTRL> \0A Child has ended execution \0A\00"
@.str.1 = [41 x i8] c"MIG-CTRL> Command launched with pid %d \0A\00"
define i32 @launch_command(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
store i8** %0, i8*** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %10, %2
store i32 -1, i32* %3
br label %34
16: ; preds = %10
%17 = load i8**, i8*** %4
%18 = load i32, i32* %5
%19 = call i8** @put_end_params(i8** %17, i32 %18)
store i8** %19, i8*** %7
%20 = call i32 (...) @fork()
store i32 %20, i32* %6
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %16
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %7
%27 = call i32 @execv(i8* %25, i8** %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @_exit(i32 2)
unreachable
30: ; preds = %16
%31 = load i32, i32* %6
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %31)
%33 = load i32, i32* %6
store i32 %33, i32* %3
br label %34
34: ; preds = %30, %15
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str.1 = [41 x i8] c"MIG-CTRL> Command launched with pid %d \0A\00"
@str = [39 x i8] c"MIG-CTRL> \0A Child has ended execution \00"
define i32 @launch_command(i8** %0, i32 %1) {
%3 = icmp slt i32 %1, 1
br i1 %3, label %18, label %4
4: ; preds = %2
%5 = load i8*, i8** %0
%6 = icmp eq i8* %5, null
br i1 %6, label %18, label %7
7: ; preds = %4
%8 = tail call i8** @put_end_params(i8** %0, i32 %1)
%9 = tail call i32 (...) @fork()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i8*, i8** %0
%13 = tail call i32 @execv(i8* %12, i8** %8)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @_exit(i32 2)
unreachable
16: ; preds = %7
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %9)
br label %18
18: ; preds = %2, %4, %16
%19 = phi i32 [ %9, %16 ], [ -1, %4 ], [ -1, %2 ]
ret i32 %19
}