#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 time_t;
struct timespec {
  int tv_sec;
  unsigned int tv_nsec;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int nanosleep(struct timespec *, struct timespec *);
int /*<<< orphan*/ printf(char *);
void msleep(unsigned int milli_seconds) {
  struct timespec req = {0};
  time_t seconds;
  seconds = (milli_seconds / 1000);
  milli_seconds = milli_seconds - (seconds * 1000);
  req.tv_sec = seconds;
  req.tv_nsec = milli_seconds * 1000000L;
  while (nanosleep(&req, &req) == -1) {
    printf("restless\n");
    continue;
  }
}


x86 assembly (clang, -O0):
<msleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%eax
imul   $0x3e8,-0x14(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
imul   $0xf4240,%rax,%rax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rsi
mov    %rsi,%rdi
call   1040 <nanosleep@plt>
cmp    $0xffffffff,%eax
jne    11a2 <msleep+0x72>
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
jmp    117c <msleep+0x4c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<msleep>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0x10(%rsp)
mov    %edi,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
imul   $0xfffffc18,%eax,%ecx
add    %edi,%ecx
mov    %eax,0x8(%rsp)
imul   $0xf4240,%ecx,%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rdi
mov    %rdi,%rsi
call   1040 <nanosleep@plt>
cmp    $0xffffffff,%eax
jne    1188 <msleep+0x68>
lea    0xe95(%rip),%r14
lea    0x8(%rsp),%rbx
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1040 <nanosleep@plt>
cmp    $0xffffffff,%eax
je     1170 <msleep+0x50>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32, i32 }
@.str = [10 x i8] c"restless\0A\00"
define void @msleep(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast %struct.timespec* %3 to i8*
%6 = load i32, i32* %2
%7 = udiv i32 %6, 1000
store i32 %7, i32* %4
%8 = load i32, i32* %2
%9 = load i32, i32* %4
%10 = mul nsw i32 %9, 1000
%11 = sub i32 %8, %10
store i32 %11, i32* %2
%12 = load i32, i32* %4
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* %2
%15 = zext i32 %14 to i64
%16 = mul nsw i64 %15, 1000000
%17 = trunc i64 %16 to i32
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i32 %17, i32* %18
br label %19
19: ; preds = %22, %1
%20 = call i32 @nanosleep(%struct.timespec* %3, %struct.timespec* %3)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %19
24: ; preds = %19
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32, i32 }
@str = [9 x i8] c"restless\00"
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 2
store i32 0, i32* %4
%5 = udiv i32 %0, 1000
%6 = mul i32 %5, -1000
%7 = add i32 %6, %0
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 %5, i32* %8
%9 = mul i32 %7, 1000000
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i32 %9, i32* %10
%11 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %2)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %17
13: ; preds = %1, %13
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%15 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %2)
%16 = icmp eq i32 %15, -1
br i1 %16, label %13, label %17
17: ; preds = %13, %1
ret void
}