#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 scalar_t__ pid_t;
typedef scalar_t__ int32_t;

/* Variables and functions */
scalar_t__ execv(char *, char **);
scalar_t__ fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, scalar_t__, ...);
int32_t OS_launch_process(char *args[]) {
  pid_t child_pid;
  if ((child_pid = fork()) >= 0) {
    if (child_pid == 0) {
      printf("plugin PID =  %d, parent pid = %d (%s, %s, %s, %s, %s)\n",
             getpid(), getppid(), args[0], args[1], args[2], args[3], args[4]);
      return (execv(args[0], args));
    } else {
      printf("parent PID =  %d, child pid = %d\n", getpid(), child_pid);
      return (child_pid);
    }
  } else
    return (-1);
}


x86 assembly (clang, -O0):
<OS_launch_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jl     1212 <OS_launch_process+0xc2>
cmpq   $0x0,-0x18(%rbp)
jne    11ea <OS_launch_process+0x9a>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x1c(%rbp),%esi
movslq %eax,%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%r8
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r9
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r10
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
lea    0xe3f(%rip),%rdi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execv@plt>
mov    %rax,-0x8(%rbp)
jmp    121a <OS_launch_process+0xca>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121a <OS_launch_process+0xca>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OS_launch_process>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     118d <OS_launch_process+0x3d>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
test   %rbx,%rbx
je     11a0 <OS_launch_process+0x50>
lea    0xeb9(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1194 <OS_launch_process+0x44>
mov    $0xffffffffffffffff,%rbx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
call   1050 <getppid@plt>
movslq %eax,%rdx
mov    (%r14),%rcx
mov    0x8(%r14),%r8
mov    0x10(%r14),%r9
movups 0x18(%r14),%xmm0
movups %xmm0,(%rsp)
lea    0xe3b(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <execv@plt>

LLVM IR (-O0):
@.str = [56 x i8] c"plugin PID = %d, parent pid = %d (%s, %s, %s, %s, %s)\0A\00"
@.str.1 = [34 x i8] c"parent PID = %d, child pid = %d\0A\00"
define i64 @OS_launch_process(i8** %0) {
%2 = alloca i64
%3 = alloca i8**
%4 = alloca i64
store i8** %0, i8*** %3
%5 = call i64 (...) @fork()
store i64 %5, i64* %4
%6 = icmp sge i64 %5, 0
br i1 %6, label %7, label %40
7: ; preds = %1
%8 = load i64, i64* %4
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %35
10: ; preds = %7
%11 = call i32 (...) @getpid()
%12 = call i32 (...) @getppid()
%13 = sext i32 %12 to i64
%14 = load i8**, i8*** %3
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = load i8**, i8*** %3
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %3
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %3
%24 = getelementptr inbounds i8*, i8** %23, i64 3
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %3
%27 = getelementptr inbounds i8*, i8** %26, i64 4
%28 = load i8*, i8** %27
%29 = call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %11, i64 %13, i8* %16, i8* %19, i8* %22, i8* %25, i8* %28)
%30 = load i8**, i8*** %3
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = load i8**, i8*** %3
%34 = call i64 @execv(i8* %32, i8** %33)
store i64 %34, i64* %2
br label %41
35: ; preds = %7
%36 = call i32 (...) @getpid()
%37 = load i64, i64* %4
%38 = call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %36, i64 %37)
%39 = load i64, i64* %4
store i64 %39, i64* %2
br label %41
40: ; preds = %1
store i64 -1, i64* %2
br label %41
41: ; preds = %40, %35, %10
%42 = load i64, i64* %2
ret i64 %42
}

LLVM IR (-O2):
@.str = [56 x i8] c"plugin PID = %d, parent pid = %d (%s, %s, %s, %s, %s)\0A\00"
@.str.1 = [34 x i8] c"parent PID = %d, child pid = %d\0A\00"
define i64 @OS_launch_process(i8** %0) {
%2 = tail call i64 (...) @fork()
%3 = icmp sgt i64 %2, -1
br i1 %3, label %4, label %24
4: ; preds = %1
%5 = icmp eq i64 %2, 0
%6 = tail call i32 (...) @getpid()
br i1 %5, label %7, label %22
7: ; preds = %4
%8 = tail call i32 (...) @getppid()
%9 = sext i32 %8 to i64
%10 = load i8*, i8** %0
%11 = getelementptr inbounds i8*, i8** %0, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %0, i64 2
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8*, i8** %0, i64 3
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %0, i64 4
%18 = load i8*, i8** %17
%19 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i32 %6, i64 %9, i8* %10, i8* %12, i8* %14, i8* %16, i8* %18)
%20 = load i8*, i8** %0
%21 = tail call i64 @execv(i8* %20, i8** %0)
br label %24
22: ; preds = %4
%23 = tail call i32 (i8*, i32, i64, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %6, i64 %2)
br label %24
24: ; preds = %1, %22, %7
%25 = phi i64 [ %21, %7 ], [ %2, %22 ], [ -1, %1 ]
ret i64 %25
}