#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ atol(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
long syscall(int, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("Please include the pid as a command line parameter.\n");
    return 1;
  }
  pid_t pid = atol(argv[1]);
  long success = syscall(290, pid);
  if (success < 0) {
    perror("Failure in myjoin");
    return 2;
  }
  printf("Success! Process joined target and has finished waiting.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1178 <main+0x38>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cf <main+0x8f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    $0x122,%edi
call   1040 <syscall@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11bc <main+0x7c>
lea    0xe8a(%rip),%rdi
call   1060 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    11cf <main+0x8f>
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
cmp    $0x1,%edi
jg     1159 <main+0x19>
lea    0xefe(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rcx
ret
mov    0x8(%rsi),%rdi
call   1050 <atol@plt>
mov    $0x122,%edi
mov    %eax,%esi
call   1040 <syscall@plt>
test   %rax,%rax
js     1183 <main+0x43>
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe76(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [53 x i8] c"Please include the pid as a command line parameter.\0A\00"
@.str.1 = [18 x i8] c"Failure in myjoin\00"
@.str.2 = [58 x i8] c"Success! Process joined target and has finished waiting.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %25
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atol(i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = call i64 @syscall(i32 290, i32 %17)
store i64 %18, i64* %7
%19 = load i64, i64* %7
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %25
23: ; preds = %12
%24 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %3
br label %25
25: ; preds = %23, %21, %10
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"Failure in myjoin\00"
@str = [57 x i8] c"Success! Process joined target and has finished waiting.\00"
@str.3 = [52 x i8] c"Please include the pid as a command line parameter.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.3, i64 0, i64 0))
br label %16
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @atol(i8* %8)
%10 = tail call i64 @syscall(i32 290, i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %16
14: ; preds = %6
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %12, %14, %4
%17 = phi i32 [ 1, %4 ], [ 2, %12 ], [ 0, %14 ]
ret i32 %17
}