#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_0;
  long member_1;
};

/* Variables and functions */
int /*<<< orphan*/ err(char *, int);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
void my_delay(int i) {
  err("<my_delay>", +1);
  struct timespec delay = {i / 1000, (long)(i % 1000) * 1000000};
  nanosleep(&delay, NULL);
  err("</my_delay>", -1);
}


x86 assembly (clang, -O0):
<my_delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
lea    0xece(%rip),%rdi
mov    $0x1,%esi
call   1040 <err@plt>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
imul   $0xf4240,%rax,%rax
mov    %rax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
lea    0xe94(%rip),%rdi
mov    $0xffffffff,%esi
call   1040 <err@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_delay>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xed2(%rip),%rdi
mov    $0x1,%esi
call   1040 <err@plt>
movslq %ebx,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,(%rsp)
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
imul   $0xf4240,%eax,%eax
cltq
mov    %rax,0x8(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
lea    0xe93(%rip),%rdi
mov    $0xffffffff,%esi
call   1040 <err@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [11 x i8] c"<my_delay>\00"
@.str.1 = [12 x i8] c"</my_delay>\00"
define void @my_delay(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
store i32 %0, i32* %2
%4 = call i32 @err(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 1)
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%6 = load i32, i32* %2
%7 = sdiv i32 %6, 1000
store i32 %7, i32* %5
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%9 = load i32, i32* %2
%10 = srem i32 %9, 1000
%11 = sext i32 %10 to i64
%12 = mul nsw i64 %11, 1000000
store i64 %12, i64* %8
%13 = call i32 @nanosleep(%struct.timespec* %3, i32* null)
%14 = call i32 @err(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 -1)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@.str = [11 x i8] c"<my_delay>\00"
@.str.1 = [12 x i8] c"</my_delay>\00"
define void @my_delay(i32 %0) {
%2 = alloca %struct.timespec
%3 = tail call i32 @err(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 1)
%4 = bitcast %struct.timespec* %2 to i8*
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%6 = sdiv i32 %0, 1000
store i32 %6, i32* %5
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%8 = srem i32 %0, 1000
%9 = mul nsw i32 %8, 1000000
%10 = sext i32 %9 to i64
store i64 %10, i64* %7
%11 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%12 = call i32 @err(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 -1)
ret void
}