#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 {
  int tv_sec;
  int /*<<< orphan*/ tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ nanosleep(struct timespec *, struct timespec *);
void sleepx(int sec) {
  struct timespec tr;
  struct timespec ts = {.tv_sec = sec, .tv_nsec = 0};
  while (1) {
    if (!nanosleep(&ts, &tr))
      break;
    if (tr.tv_sec <= 0)
      break;
    ts = tr;
  };
}


x86 assembly (clang, -O0):
<sleepx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <nanosleep@plt>
cmp    $0x0,%eax
jne    1143 <sleepx+0x33>
jmp    115f <sleepx+0x4f>
cmpl   $0x0,-0x10(%rbp)
jg     1152 <sleepx+0x42>
jmp    115f <sleepx+0x4f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1128 <sleepx+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleepx>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,0x8(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <nanosleep@plt>
test   %eax,%eax
je     1170 <sleepx+0x60>
cmpl   $0x0,0x10(%rsp)
jle    1170 <sleepx+0x60>
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <nanosleep@plt>
test   %eax,%eax
je     1170 <sleepx+0x60>
cmpl   $0x0,0x10(%rsp)
jg     1150 <sleepx+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define void @sleepx(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
store i32 %0, i32* %2
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%6 = load i32, i32* %2
store i32 %6, i32* %5
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i32 0, i32* %7
br label %8
8: ; preds = %1, %17
%9 = call i32 @nanosleep(%struct.timespec* %4, %struct.timespec* %3)
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %8
br label %20
12: ; preds = %8
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %12
br label %20
17: ; preds = %12
%18 = bitcast %struct.timespec* %4 to i8*
%19 = bitcast %struct.timespec* %3 to i8*
br label %8
20: ; preds = %16, %11
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define void @sleepx(i32 %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.timespec*
%4 = alloca i64
%5 = bitcast i64* %4 to %struct.timespec*
%6 = bitcast i64* %2 to i8*
%7 = bitcast i64* %4 to i8*
%8 = bitcast i64* %4 to i32*
store i32 %0, i32* %8
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i64 0, i32 1
store i32 0, i32* %9
%10 = call i32 @nanosleep(%struct.timespec* %5, %struct.timespec* %3)
%11 = icmp eq i32 %10, 0
%12 = bitcast i64* %2 to i32*
%13 = load i32, i32* %12
%14 = icmp slt i32 %13, 1
%15 = select i1 %11, i1 true, i1 %14
br i1 %15, label %23, label %16
16: ; preds = %1, %16
%17 = load i64, i64* %2
store i64 %17, i64* %4
%18 = call i32 @nanosleep(%struct.timespec* %5, %struct.timespec* %3)
%19 = icmp eq i32 %18, 0
%20 = load i32, i32* %12
%21 = icmp slt i32 %20, 1
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %23, label %16
23: ; preds = %16, %1
ret void
}