#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int poll(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void test_sleep(void *ptr) {
  int *ptimeout = (int *)ptr;
  int ret;
  ret = poll(NULL, 0, *ptimeout);
  if (ret != 0) {
    fprintf(stderr, "poll returned %d (%s)\n", ret, strerror(errno));
  }
}


x86 assembly (clang, -O0):
<test_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1040 <poll@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1197 <test_sleep+0x67>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    %rax,%rcx
lea    0xe6e(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sleep>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%edx
xor    %edi,%edi
xor    %esi,%esi
call   1040 <poll@plt>
test   %eax,%eax
je     1174 <test_sleep+0x44>
mov    %eax,%ebx
mov    0x2e95(%rip),%rax
mov    (%rax),%ebp
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9e(%rip),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
mov    %rax,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"poll returned %d (%s)\0A\00"
@errno = global i32 0
define void @test_sleep(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = bitcast i8* %5 to i32*
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = load i32, i32* %7
%9 = call i32 @poll(i32* null, i32 0, i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i32, i32* %4
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %16)
br label %18
18: ; preds = %12, %1
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"poll returned %d (%s)\0A\00"
@errno = global i32 0
define void @test_sleep(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
%4 = tail call i32 @poll(i32* null, i32 0, i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %4, i8* %9)
br label %11
11: ; preds = %6, %1
ret void
}