#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 timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          struct timeval *);
void scsleep(int ms) {
  struct timeval tv;
  if (!ms)
    return;
  tv.tv_sec = (ms + 1) / 1000;
  tv.tv_usec = (ms % 1000) * 1000;
  select(0, NULL, NULL, NULL, &tv);
}


x86 assembly (clang, -O0):
<scsleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    112a <scsleep+0x1a>
jmp    1164 <scsleep+0x54>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0xc(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <select@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scsleep>:
test   %edi,%edi
je     116e <scsleep+0x5e>
push   %rax
lea    0x1(%rdi),%eax
cltq
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
mov    %eax,(%rsp)
movslq %edi,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%eax
sub    %eax,%edi
imul   $0x3e8,%edi,%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%r8
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <select@plt>
add    $0x8,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @scsleep(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timeval
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %7, label %6
6: ; preds = %1
br label %17
7: ; preds = %1
%8 = load i32, i32* %2
%9 = add nsw i32 %8, 1
%10 = sdiv i32 %9, 1000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* %2
%13 = srem i32 %12, 1000
%14 = mul nsw i32 %13, 1000
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i32 %14, i32* %15
%16 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %3)
br label %17
17: ; preds = %7, %6
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define void @scsleep(i32 %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = icmp eq i32 %0, 0
br i1 %4, label %13, label %5
5: ; preds = %1
%6 = add nsw i32 %0, 1
%7 = sdiv i32 %6, 1000
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 %7, i32* %8
%9 = srem i32 %0, 1000
%10 = mul nsw i32 %9, 1000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 %10, i32* %11
%12 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
br label %13
13: ; preds = %1, %5
ret void
}