#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*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ printf(char *, intptr_t);
int waitpid(int, int *, int /*<<< orphan*/);
void *PrintHello(void *args) {
  intptr_t thread_arg;
  pid_t p;
  int status;
  char *argv[] = {"hello"};
  p = fork();
  switch (p) {
  case -1:
    return NULL;
  case 0:
    execvp("./a.sh", argv);
    exit(127);
    break;
  default:
    if (waitpid(p, &status, 0) == -1)
      return NULL;
    return NULL;
  }
  thread_arg = (intptr_t)args;
  printf("Hello from thread %ld\n", thread_arg);
  return NULL;
}


x86 assembly (clang, -O0):
<PrintHello>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2cc5(%rip),%rax
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0xffffffff,%eax
je     1185 <PrintHello+0x45>
jmp    1175 <PrintHello+0x35>
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     1192 <PrintHello+0x52>
jmp    11ac <PrintHello+0x6c>
movq   $0x0,-0x8(%rbp)
jmp    11d8 <PrintHello+0x98>
lea    -0x28(%rbp),%rsi
lea    0xe69(%rip),%rdi
call   1040 <execvp@plt>
mov    $0x7f,%edi
call   1050 <exit@plt>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    11d0 <PrintHello+0x90>
movq   $0x0,-0x8(%rbp)
jmp    11d8 <PrintHello+0x98>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrintHello>:
sub    $0x18,%rsp
lea    0xeb5(%rip),%rax
mov    %rax,0x8(%rsp)
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     116e <PrintHello+0x2e>
test   %eax,%eax
je     1175 <PrintHello+0x35>
lea    0x14(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1030 <waitpid@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
lea    0xe8a(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <execvp@plt>
mov    $0x7f,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"hello\00"
@__const.PrintHello.argv = [1 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0)]
@.str.1 = [7 x i8] c"./a.sh\00"
define i8* @PrintHello(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1 x i8*]
store i8* %0, i8** %3
%8 = bitcast [1 x i8*]* %7 to i8*
%9 = call i32 (...) @fork()
store i32 %9, i32* %5
%10 = load i32, i32* %5
switch i32 %10, label %16 [
i32 -1, label %11
i32 0, label %12
]
11: ; preds = %1
store i8* null, i8** %2
br label %22
12: ; preds = %1
%13 = getelementptr inbounds [1 x i8*], [1 x i8*]* %7, i64 0, i64 0
%14 = call i32 @execvp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %13)
%15 = call i32 @exit(i32 127)
unreachable
16: ; preds = %1
%17 = load i32, i32* %5
%18 = call i32 @waitpid(i32 %17, i32* %6, i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %16
store i8* null, i8** %2
br label %22
21: ; preds = %16
store i8* null, i8** %2
br label %22
22: ; preds = %21, %20, %11
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str = [6 x i8] c"hello\00"
@.str.1 = [7 x i8] c"./a.sh\00"
define noalias i8* @PrintHello(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = alloca [1 x i8*]
%4 = bitcast i32* %2 to i8*
%5 = bitcast [1 x i8*]* %3 to i8*
%6 = bitcast [1 x i8*]* %3 to i64*
store i64 ptrtoint ([6 x i8]* @.str to i64), i64* %6
%7 = tail call i32 (...) @fork()
switch i32 %7, label %12 [
i32 -1, label %14
i32 0, label %8
]
8: ; preds = %1
%9 = getelementptr inbounds [1 x i8*], [1 x i8*]* %3, i64 0, i64 0
%10 = call i32 @execvp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %9)
%11 = call i32 @exit(i32 127)
unreachable
12: ; preds = %1
%13 = call i32 @waitpid(i32 %7, i32* %2, i32 0)
br label %14
14: ; preds = %12, %1
ret i8* null
}