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

/* Variables and functions */
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int timewaitfor(int whundredths) {
  int secs = whundredths / 100, hundredths = whundredths - (100 * secs);
  long nanos = ((long)hundredths) * ((long)10000000);
  struct timespec waitfor = {0, 0};
  if (whundredths >= 1 && secs <= 999) {
    waitfor.tv_sec = secs;
    waitfor.tv_nsec = nanos;
    nanosleep(&waitfor, NULL);
  }
  return (1);
}


x86 assembly (clang, -O0):
<timewaitfor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
imul   $0x64,-0x8(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
imul   $0x989680,%rax,%rax
mov    %rax,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1040 <memset@plt>
cmpl   $0x1,-0x4(%rbp)
jl     1196 <timewaitfor+0x76>
cmpl   $0x3e7,-0x8(%rbp)
jg     1196 <timewaitfor+0x76>
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timewaitfor>:
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
lea    -0x1(%rdi),%eax
cmp    $0x1869e,%eax
ja     1166 <timewaitfor+0x56>
movslq %edi,%rax
imul   $0x51eb851f,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0xffffff9c,%eax,%ecx
add    %edi,%ecx
movslq %ecx,%rcx
imul   $0x989680,%rcx,%rcx
mov    %eax,(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
mov    $0x1,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64, i32, i32 }
define i32 @timewaitfor(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca %struct.timespec
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = sdiv i32 %7, 100
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = load i32, i32* %3
%11 = mul nsw i32 100, %10
%12 = sub nsw i32 %9, %11
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = mul nsw i64 %14, 10000000
store i64 %15, i64* %5
%16 = bitcast %struct.timespec* %6 to i8*
%17 = load i32, i32* %2
%18 = icmp sge i32 %17, 1
br i1 %18, label %19, label %28
19: ; preds = %1
%20 = load i32, i32* %3
%21 = icmp sle i32 %20, 999
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i32, i32* %3
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i64, i64* %5
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
store i64 %25, i64* %26
%27 = call i32 @nanosleep(%struct.timespec* %6, i32* null)
br label %28
28: ; preds = %22, %19, %1
ret i32 1
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64, i32, i32 }
define i32 @timewaitfor(i32 %0) {
%2 = alloca %struct.timespec
%3 = sdiv i32 %0, 100
%4 = bitcast %struct.timespec* %2 to i8*
%5 = add i32 %0, -1
%6 = icmp ult i32 %5, 99999
br i1 %6, label %7, label %15
7: ; preds = %1
%8 = mul nsw i32 %3, -100
%9 = add i32 %8, %0
%10 = sext i32 %9 to i64
%11 = mul nsw i64 %10, 10000000
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 %3, i32* %12
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 %11, i64* %13
%14 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
br label %15
15: ; preds = %7, %1
ret i32 1
}