#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 execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setpgid(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
void *threadCall(void *givenCmds) {
  char **givenData = givenCmds;
  for (; 0;)
    printf("execvp(%s,double pointer to givenData)\n", givenData[0]);
  int i = -1;
  for (; 0;)
    printf("Cmds to pass %s, %s, %s, %s, %s\n", givenData[0], givenData[1],
           givenData[2], givenData[3], givenData[4]);
  i = fork();
  if (i == 0) {
    fclose(stdout);
    setpgid(0, 0);
    for (; 0;)
      printf("Still displaying output\n");
    i = execvp(givenData[0], givenData);
    if (i == -1) {
      exit(1);
    }
  } else {
    return NULL;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<threadCall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
test   $0x1,%al
jne    1183 <threadCall+0x23>
jmp    119d <threadCall+0x3d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1174 <threadCall+0x14>
movl   $0xffffffff,-0x1c(%rbp)
xor    %eax,%eax
test   $0x1,%al
jne    11b3 <threadCall+0x53>
jmp    11ed <threadCall+0x8d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%r8
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%r9
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a4 <threadCall+0x44>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1266 <threadCall+0x106>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
xor    %esi,%esi
mov    %esi,%edi
call   1060 <setpgid@plt>
xor    %eax,%eax
test   $0x1,%al
jne    1227 <threadCall+0xc7>
jmp    123a <threadCall+0xda>
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1218 <threadCall+0xb8>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <execvp@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1261 <threadCall+0x101>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1273 <threadCall+0x113>
movq   $0x0,-0x8(%rbp)
jmp    127b <threadCall+0x11b>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<threadCall>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    1186 <threadCall+0x36>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1030 <fclose@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1050 <setpgid@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1040 <execvp@plt>
cmp    $0xffffffff,%eax
je     118a <threadCall+0x3a>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"execvp(%s,double pointer to givenData)\0A\00"
@.str.1 = [33 x i8] c"Cmds to pass %s, %s, %s, %s, %s\0A\00"
@stdout = global i32 0
@.str.2 = [25 x i8] c"Still displaying output\0A\00"
define i8* @threadCall(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = bitcast i8* %6 to i8**
store i8** %7, i8*** %4
br label %8
8: ; preds = %9, %1
br i1 false, label %9, label %14
9: ; preds = %8
%10 = load i8**, i8*** %4
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %8
14: ; preds = %8
store i32 -1, i32* %5
br label %15
15: ; preds = %16, %14
br i1 false, label %16, label %33
16: ; preds = %15
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %4
%27 = getelementptr inbounds i8*, i8** %26, i64 3
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %4
%30 = getelementptr inbounds i8*, i8** %29, i64 4
%31 = load i8*, i8** %30
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %19, i8* %22, i8* %25, i8* %28, i8* %31)
br label %15
33: ; preds = %15
%34 = call i32 (...) @fork()
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %55
37: ; preds = %33
%38 = load i32, i32* @stdout
%39 = call i32 @fclose(i32 %38)
%40 = call i32 @setpgid(i32 0, i32 0)
br label %41
41: ; preds = %42, %37
br i1 false, label %42, label %44
42: ; preds = %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %41
44: ; preds = %41
%45 = load i8**, i8*** %4
%46 = getelementptr inbounds i8*, i8** %45, i64 0
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %4
%49 = call i32 @execvp(i8* %47, i8** %48)
store i32 %49, i32* %5
%50 = load i32, i32* %5
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %44
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %44
br label %56
55: ; preds = %33
store i8* null, i8** %2
br label %57
56: ; preds = %54
store i8* null, i8** %2
br label %57
57: ; preds = %56, %55
%58 = load i8*, i8** %2
ret i8* %58
}

LLVM IR (-O2):
@stdout = global i32 0
define noalias i8* @threadCall(i8* %0) {
%2 = bitcast i8* %0 to i8**
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %1
%6 = load i32, i32* @stdout
%7 = tail call i32 @fclose(i32 %6)
%8 = tail call i32 @setpgid(i32 0, i32 0)
%9 = load i8*, i8** %2
%10 = tail call i32 @execvp(i8* %9, i8** %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %5
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %5, %1
ret i8* null
}