#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;
  scalar_t__ events;
};

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


x86 assembly (clang, -O0):
<thread_poll>:
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,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <_poll@plt>
mov    $0x0,%al
call   1030 <gettid@plt>
mov    %eax,%esi
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_poll>:
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,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   1050 <_poll@plt>
xor    %eax,%eax
call   1030 <gettid@plt>
lea    0xe92(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i64 }
@.str = [11 x i8] c"%d: START\0A\00"
@.str.1 = [9 x i8] c"%d: END\0A\00"
define void @thread_poll(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 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %4, i32 0, i32 1
store i64 0, i64* %11
%12 = call i32 @_poll(%struct.pollfd* %4, i32 1, i32 -1)
%13 = call i32 (...) @gettid()
%14 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %13)
ret void
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i64 }
@.str = [11 x i8] c"%d: START\0A\00"
@.str.1 = [9 x i8] c"%d: END\0A\00"
define void @thread_poll(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 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i64 0, i32 1
store i64 0, i64* %9
%10 = call i32 @_poll(%struct.pollfd* %2, i32 1, i32 -1)
%11 = call i32 (...) @gettid()
%12 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %11)
ret void
}