#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 */
struct pollfd {
  int fd;
  int /*<<< orphan*/ events;
};

/* Variables and functions */
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ _poll(struct pollfd *, int, int);
int gettid();
int /*<<< orphan*/ printf(char *, int);
void thread_pollin(void *args) {
  int fd = (int)args;
  struct pollfd pfd;
  printf("%d: START\n", gettid());
  pfd.fd = fd;
  pfd.events = POLLIN;
  _poll(&pfd, 1, -1);
  printf("%d: END\n", gettid());
}


x86 assembly (clang, -O0):
<thread_pollin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <gettid@plt>
mov    %eax,%esi
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <_poll@plt>
mov    $0x0,%al
call   1030 <gettid@plt>
mov    %eax,%esi
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_pollin>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <gettid@plt>
lea    0xeba(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %ebx,0x8(%rsp)
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <_poll@plt>
xor    %eax,%eax
call   1030 <gettid@plt>
lea    0xe8b(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
@.str = [11 x i8] c"%d: START\0A\00"
@POLLIN = global i32 0
@.str.1 = [9 x i8] c"%d: END\0A\00"
define void @thread_pollin(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.pollfd
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = ptrtoint i8* %5 to i32
store i32 %6, i32* %3
%7 = call i32 (...) @gettid()
%8 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %3
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @POLLIN
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 1
store i32 %11, i32* %12
%13 = call i32 @_poll(%struct.pollfd* %4, i32 1, i32 -1)
%14 = call i32 (...) @gettid()
%15 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %14)
ret void
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
@.str = [11 x i8] c"%d: START\0A\00"
@POLLIN = global i32 0
@.str.1 = [9 x i8] c"%d: END\0A\00"
define void @thread_pollin(i8* %0) {
%2 = alloca %struct.pollfd
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = bitcast %struct.pollfd* %2 to i8*
%6 = tail call i32 (...) @gettid()
%7 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 0
store i32 %4, i32* %8
%9 = load i32, i32* @POLLIN
%10 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 1
store i32 %9, i32* %10
%11 = call i32 @_poll(%struct.pollfd* %2, i32 1, i32 -1)
%12 = call i32 (...) @gettid()
%13 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %12)
ret void
}