#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*/ SYS_gettid;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ ksft_print_msg(char *, int /*<<< orphan*/,
                                  int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ syscall(int /*<<< orphan*/);
void *test_pidfd_poll_leader_exit_thread(void *priv) {
  ksft_print_msg("Child Thread: starting. pid %d tid %d ; and sleeping\n",
                 getpid(), syscall(SYS_gettid));
  sleep(3);
  ksft_print_msg("Child Thread: DONE. pid %d tid %d\n", getpid(),
                 syscall(SYS_gettid));
  return NULL;
}


x86 assembly (clang, -O0):
<test_pidfd_poll_leader_exit_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e8b(%rip),%rax
mov    (%rax),%edi
call   1040 <syscall@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe90(%rip),%rdi
call   1050 <ksft_print_msg@plt>
mov    $0x3,%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1040 <syscall@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe93(%rip),%rdi
call   1050 <ksft_print_msg@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_pidfd_poll_leader_exit_thread>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
mov    0x2e94(%rip),%r14
mov    (%r14),%edi
call   1040 <syscall@plt>
lea    0xe9d(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <ksft_print_msg@plt>
mov    $0x3,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
mov    (%r14),%edi
call   1040 <syscall@plt>
lea    0xea8(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1050 <ksft_print_msg@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [54 x i8] c"Child Thread: starting. pid %d tid %d ; and sleeping\0A\00"
@SYS_gettid = global i32 0
@.str.1 = [35 x i8] c"Child Thread: DONE. pid %d tid %d\0A\00"
define i8* @test_pidfd_poll_leader_exit_thread(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = call i32 (...) @getpid()
%4 = load i32, i32* @SYS_gettid
%5 = call i32 @syscall(i32 %4)
%6 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %5)
%7 = call i32 @sleep(i32 3)
%8 = call i32 (...) @getpid()
%9 = load i32, i32* @SYS_gettid
%10 = call i32 @syscall(i32 %9)
%11 = call i32 @ksft_print_msg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %10)
ret i8* null
}

LLVM IR (-O2):
@.str = [54 x i8] c"Child Thread: starting. pid %d tid %d ; and sleeping\0A\00"
@SYS_gettid = global i32 0
@.str.1 = [35 x i8] c"Child Thread: DONE. pid %d tid %d\0A\00"
define noalias i8* @test_pidfd_poll_leader_exit_thread(i8* nocapture readnone %0) {
%2 = tail call i32 (...) @getpid()
%3 = load i32, i32* @SYS_gettid
%4 = tail call i32 @syscall(i32 %3)
%5 = tail call i32 @ksft_print_msg(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %4)
%6 = tail call i32 @sleep(i32 3)
%7 = tail call i32 (...) @getpid()
%8 = load i32, i32* @SYS_gettid
%9 = tail call i32 @syscall(i32 %8)
%10 = tail call i32 @ksft_print_msg(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %9)
ret i8* null
}