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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ wait(int *);
void *TestThread(void *not_used) {
  pthread_t iAm = pthread_self();
  int status;
  switch (fork()) {
  case -1:
    exit(1);
  case 0:
    if (iAm != pthread_self())
      exit(1);
    else
      exit(0);
    break;
  default:
    wait(&status);
    if (status != 0)
      exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<TestThread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
mov    %al,-0x15(%rbp)
call   1030 <pthread_self@plt>
mov    %eax,%ecx
mov    -0x15(%rbp),%al
mov    %ecx,-0xc(%rbp)
call   1060 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0xffffffff,%eax
je     1186 <TestThread+0x46>
jmp    1176 <TestThread+0x36>
mov    -0x14(%rbp),%eax
test   %eax,%eax
je     1190 <TestThread+0x50>
jmp    11bb <TestThread+0x7b>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <pthread_self@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
je     11b4 <TestThread+0x74>
mov    $0x1,%edi
call   1040 <exit@plt>
xor    %edi,%edi
call   1040 <exit@plt>
lea    -0x10(%rbp),%rdi
call   1050 <wait@plt>
cmpl   $0x0,-0x10(%rbp)
je     11d8 <TestThread+0x98>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    11dd <TestThread+0x9d>
xor    %edi,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<TestThread>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <pthread_self@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1179 <TestThread+0x39>
cmp    $0xffffffff,%eax
je     116f <TestThread+0x2f>
lea    0xc(%rsp),%rdi
call   1050 <wait@plt>
cmpl   $0x0,0xc(%rsp)
je     1184 <TestThread+0x44>
mov    $0x1,%edi
call   1040 <exit@plt>
xor    %eax,%eax
call   1030 <pthread_self@plt>
cmp    %eax,%ebx
jne    116f <TestThread+0x2f>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
define i8* @TestThread(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @pthread_self()
store i32 %5, i32* %3
%6 = call i32 (...) @fork()
switch i32 %6, label %17 [
i32 -1, label %7
i32 0, label %9
]
7: ; preds = %1
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 (...) @pthread_self()
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %9
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %1
%18 = call i32 @wait(i32* %4)
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %17
br label %24
24: ; preds = %23
%25 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
define noalias i8* @TestThread(i8* nocapture readnone %0) {
%2 = alloca i32
%3 = tail call i32 (...) @pthread_self()
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (...) @fork()
switch i32 %5, label %15 [
i32 -1, label %6
i32 0, label %8
]
6: ; preds = %1
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call i32 (...) @pthread_self()
%10 = icmp eq i32 %3, %9
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %8
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %1
%16 = call i32 @wait(i32* %2)
%17 = load i32, i32* %2
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %15
%22 = call i32 @exit(i32 0)
unreachable
}