#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*/ execv(char *, char *const *);
int getpid();
int /*<<< orphan*/ printf(char *, ...);
void *work(void *param) {
  printf("I'm %d, PID: %d\n", (int)param, getpid());
  char *const argv[] = {"echo", "test", NULL};
  execv("/usr/bin/echo", argv);
  printf("Should never get here\n");
}


x86 assembly (clang, -O0):
<work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x34(%rbp),%esi
mov    %eax,%edx
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2c9c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c99(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c96(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x30(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1050 <execv@plt>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xeaa(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2ca8(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2c8c(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe97(%rip),%rdi
mov    %rsp,%rsi
call   1060 <execv@plt>
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"I'm %d, PID: %d\0A\00"
@.str.1 = [5 x i8] c"echo\00"
@.str.2 = [5 x i8] c"test\00"
@__const.work.argv = [3 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [14 x i8] c"/usr/bin/echo\00"
@.str.4 = [23 x i8] c"Should never get here\0A\00"
define i8* @work(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [3 x i8*]
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = ptrtoint i8* %5 to i32
%7 = call i32 (...) @getpid()
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %7)
%9 = bitcast [3 x i8*]* %4 to i8*
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%11 = call i32 @execv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%13 = load i8*, i8** %2
ret i8* %13
}

LLVM IR (-O2):
@.str = [17 x i8] c"I'm %d, PID: %d\0A\00"
@.str.1 = [5 x i8] c"echo\00"
@.str.2 = [5 x i8] c"test\00"
@__const.work.argv = [3 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i8* null]
@.str.3 = [14 x i8] c"/usr/bin/echo\00"
@str = [22 x i8] c"Should never get here\00"
define noalias i8* @work(i8* %0) {
%2 = alloca [3 x i8*]
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = bitcast [3 x i8*]* %2 to i8*
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%9 = call i32 @execv(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %8)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
ret i8* undef
}