#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 tv_nsec;
};

/* Variables and functions */
scalar_t__ nanosleep(struct timespec *, struct timespec *);
int smm_errno_update(int /*<<< orphan*/);
int smm_sleep(int sec, int usec) {
  struct timespec require, remain;
  require.tv_sec = sec;
  require.tv_nsec = usec * 1000;
  while (nanosleep(&require, &remain) < 0) {
    require = remain;
  }
  return smm_errno_update(0);
}


x86 assembly (clang, -O0):
<smm_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x10(%rbp)
imul   $0x3e8,-0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <nanosleep@plt>
cmp    $0x0,%rax
jge    1162 <smm_sleep+0x42>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    113e <smm_sleep+0x1e>
xor    %edi,%edi
call   1040 <smm_errno_update@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smm_sleep>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,0x8(%rsp)
imul   $0x3e8,%esi,%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <nanosleep@plt>
test   %rax,%rax
jns    117a <smm_sleep+0x5a>
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <nanosleep@plt>
test   %rax,%rax
js     1160 <smm_sleep+0x40>
xor    %edi,%edi
call   1040 <smm_errno_update@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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