#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 timespec {
  unsigned int tv_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
scalar_t__ nanosleep(struct timespec *, struct timespec *);
void upm_delay(unsigned int time) {
  if (time <= 0)
    time = 1;
  struct timespec delay_time;
  delay_time.tv_sec = time;
  delay_time.tv_nsec = 0;
  while (nanosleep(&delay_time, &delay_time) && errno == EINTR)
    ;
}


x86 assembly (clang, -O0):
<upm_delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
ja     112c <upm_delay+0x1c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x18(%rbp),%rsi
mov    %rsi,%rdi
call   1030 <nanosleep@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     1172 <upm_delay+0x62>
mov    0x2e81(%rip),%rax
mov    (%rax),%rax
mov    0x2e6f(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1182 <upm_delay+0x72>
jmp    1187 <upm_delay+0x77>
jmp    113a <upm_delay+0x2a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<upm_delay>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
mov    $0x1,%eax
cmovne %edi,%eax
mov    %eax,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rbx
mov    0x2ea7(%rip),%r14
mov    0x2e98(%rip),%r15
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <nanosleep@plt>
test   %rax,%rax
je     1158 <upm_delay+0x48>
mov    (%r15),%rax
cmp    %rax,(%r14)
je     1140 <upm_delay+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@errno = global i64 0
@EINTR = global i64 0
define void @upm_delay(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp ule i32 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 1, i32* %2
br label %7
7: ; preds = %6, %1
%8 = load i32, i32* %2
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 0, i64* %10
br label %11
11: ; preds = %20, %7
%12 = call i64 @nanosleep(%struct.timespec* %3, %struct.timespec* %3)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i64, i64* @errno
%16 = load i64, i64* @EINTR
%17 = icmp eq i64 %15, %16
br label %18
18: ; preds = %14, %11
%19 = phi i1 [ false, %11 ], [ %17, %14 ]
br i1 %19, label %20, label %21
20: ; preds = %18
br label %11
21: ; preds = %18
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@errno = global i64 0
@EINTR = global i64 0
define void @upm_delay(i32 %0) {
%2 = alloca %struct.timespec
%3 = icmp eq i32 %0, 0
%4 = select i1 %3, i32 1, i32 %0
%5 = bitcast %struct.timespec* %2 to i8*
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 %4, i32* %6
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 0, i64* %7
br label %8
8: ; preds = %8, %1
%9 = call i64 @nanosleep(%struct.timespec* %2, %struct.timespec* %2)
%10 = icmp ne i64 %9, 0
%11 = load i64, i64* @errno
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %11, %12
%14 = select i1 %10, i1 %13, i1 false
br i1 %14, label %8, label %15
15: ; preds = %8
ret void
}