#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*/ timer_t;
typedef int /*<<< orphan*/ timeout;
struct timeval {
  int tv_sec;
};

/* Variables and functions */
scalar_t__ EINTR;
int check_alarmcount(int, int const);
int check_timer_latency(int, int const);
scalar_t__ errno;
int /*<<< orphan*/ memset(struct timeval *, int /*<<< orphan*/, int);
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int setup_timer(int, int, int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ timer_delete(int /*<<< orphan*/);
int do_timer_oneshot(int clock_id, int flags) {
  timer_t tm1;
  const int interval = 0;
  struct timeval timeout;
  int err;
  err = setup_timer(clock_id, flags, interval, &tm1);
  if (err)
    return err == 1 ? 0 : err;
  memset(&timeout, 0, sizeof(timeout));
  timeout.tv_sec = 5;
  do {
    err = select(0, NULL, NULL, NULL, &timeout);
  } while (err == -1 && errno == EINTR);
  timer_delete(tm1);
  err = check_timer_latency(flags, interval);
  err |= check_alarmcount(flags, interval);
  return err;
}


x86 assembly (clang, -O0):
<do_timer_oneshot>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
xor    %edx,%edx
lea    -0x10(%rbp),%rcx
call   1030 <setup_timer@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11b8 <do_timer_oneshot+0x58>
cmpl   $0x1,-0x1c(%rbp)
jne    11a7 <do_timer_oneshot+0x47>
xor    %eax,%eax
mov    %eax,-0x20(%rbp)
jmp    11ad <do_timer_oneshot+0x4d>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1246 <do_timer_oneshot+0xe6>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
movl   $0x5,-0x18(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1070 <select@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
jne    1210 <do_timer_oneshot+0xb0>
mov    0x2de3(%rip),%rax
mov    (%rax),%rax
mov    0x2dd1(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    11cf <do_timer_oneshot+0x6f>
mov    -0x10(%rbp),%edi
call   1060 <timer_delete@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1080 <check_timer_latency@plt>
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1040 <check_alarmcount@plt>
or     -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_timer_oneshot>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
xor    %ebx,%ebx
lea    0x4(%rsp),%rcx
xor    %edx,%edx
call   1030 <setup_timer@plt>
test   %eax,%eax
je     1184 <do_timer_oneshot+0x24>
cmp    $0x1,%eax
cmovne %eax,%ebx
jmp    11f3 <do_timer_oneshot+0x93>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
movl   $0x5,(%rsp)
mov    0x2e3c(%rip),%rbp
mov    0x2e2d(%rip),%rbx
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1070 <select@plt>
cmp    $0xffffffff,%eax
jne    11ce <do_timer_oneshot+0x6e>
mov    (%rbx),%rax
cmp    %rax,0x0(%rbp)
je     11b0 <do_timer_oneshot+0x50>
mov    0x4(%rsp),%edi
call   1060 <timer_delete@plt>
mov    %r15d,%edi
xor    %esi,%esi
call   1080 <check_timer_latency@plt>
mov    %eax,%r14d
mov    %r15d,%edi
xor    %esi,%esi
call   1040 <check_alarmcount@plt>
mov    %eax,%ebx
or     %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @do_timer_oneshot(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %7
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = call i32 @setup_timer(i32 %10, i32 %11, i32 0, i32* %6)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %19
18: ; preds = %15
br label %21
19: ; preds = %15
%20 = load i32, i32* %9
br label %21
21: ; preds = %19, %18
%22 = phi i32 [ 0, %18 ], [ %20, %19 ]
store i32 %22, i32* %3
br label %47
23: ; preds = %2
%24 = call i32 @memset(%struct.timeval* %8, i32 0, i32 4)
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
store i32 5, i32* %25
br label %26
26: ; preds = %35, %23
%27 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %8)
store i32 %27, i32* %9
br label %28
28: ; preds = %26
%29 = load i32, i32* %9
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i64, i64* @errno
%33 = load i64, i64* @EINTR
%34 = icmp eq i64 %32, %33
br label %35
35: ; preds = %31, %28
%36 = phi i1 [ false, %28 ], [ %34, %31 ]
br i1 %36, label %26, label %37
37: ; preds = %35
%38 = load i32, i32* %6
%39 = call i32 @timer_delete(i32 %38)
%40 = load i32, i32* %5
%41 = call i32 @check_timer_latency(i32 %40, i32 0)
store i32 %41, i32* %9
%42 = load i32, i32* %5
%43 = call i32 @check_alarmcount(i32 %42, i32 0)
%44 = load i32, i32* %9
%45 = or i32 %44, %43
store i32 %45, i32* %9
%46 = load i32, i32* %9
store i32 %46, i32* %3
br label %47
47: ; preds = %37, %21
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @do_timer_oneshot(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = call i32 @setup_timer(i32 %0, i32 %1, i32 0, i32* %3)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = icmp eq i32 %7, 1
%11 = select i1 %10, i32 0, i32 %7
br label %28
12: ; preds = %2
%13 = call i32 @memset(%struct.timeval* %4, i32 0, i32 4)
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 5, i32* %14
br label %15
15: ; preds = %15, %12
%16 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %4)
%17 = icmp eq i32 %16, -1
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINTR
%20 = icmp eq i64 %18, %19
%21 = select i1 %17, i1 %20, i1 false
br i1 %21, label %15, label %22
22: ; preds = %15
%23 = load i32, i32* %3
%24 = call i32 @timer_delete(i32 %23)
%25 = call i32 @check_timer_latency(i32 %1, i32 0)
%26 = call i32 @check_alarmcount(i32 %1, i32 0)
%27 = or i32 %26, %25
br label %28
28: ; preds = %22, %9
%29 = phi i32 [ %11, %9 ], [ %27, %22 ]
ret i32 %29
}