#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 member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void msleep(int ms) {
  struct timespec ts = {0, ms * 1000 * 1000};
  if (nanosleep(&ts, NULL)) {
    fprintf(stderr, "nanosleep() failed: %s\n", strerror(errno));
    exit(1);
  }
}


x86 assembly (clang, -O0):
<msleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
imul   $0x3e8,-0x4(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
cmp    $0x0,%rax
je     11af <msleep+0x6f>
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe60(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msleep>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0x8(%rsp)
imul   $0xf4240,%edi,%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
test   %rax,%rax
jne    116e <msleep+0x2e>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e6b(%rip),%rax
mov    (%rax),%ebx
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe74(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@stderr = global i32 0
@.str = [24 x i8] c"nanosleep() failed: %s\0A\00"
@errno = global i32 0
define void @msleep(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
store i32 %0, i32* %2
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 0, i32* %4
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%6 = load i32, i32* %2
%7 = mul nsw i32 %6, 1000
%8 = mul nsw i32 %7, 1000
store i32 %8, i32* %5
%9 = call i64 @nanosleep(%struct.timespec* %3, i32* null)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* @errno
%14 = call i8* @strerror(i32 %13)
%15 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %1
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@stderr = global i32 0
@.str = [24 x i8] c"nanosleep() failed: %s\0A\00"
@errno = global i32 0
define void @msleep(i32 %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 0, i32* %4
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%6 = mul i32 %0, 1000000
store i32 %6, i32* %5
%7 = call i64 @nanosleep(%struct.timespec* %2, i32* null)
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %1
ret void
}