#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_nsec;
  int tv_sec;
};

/* Variables and functions */
int nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int nanosleep0(char *s, size_t length) {
  struct timespec req;
  sscanf(s, "%ld\n", &req.tv_nsec);
  req.tv_sec = req.tv_nsec / 1000000000;
  req.tv_nsec %= 1000000000;
  return nanosleep(&req, NULL);
}


x86 assembly (clang, -O0):
<nanosleep0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rdx
lea    0xec1(%rip),%rsi
call   1040 <sscanf@plt>
mov    -0x18(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3b9aca00,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nanosleep0>:
push   %rbx
sub    $0x10,%rsp
lea    0xed4(%rip),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdx
call   1040 <sscanf@plt>
movslq 0x8(%rsp),%rax
imul   $0x44b82fa1,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x3c,%rcx
add    %edx,%ecx
mov    %ecx,0xc(%rsp)
imul   $0x3b9aca00,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x8(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [5 x i8] c"%ld\0A\00"
define i32 @nanosleep0(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.timespec
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%8 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %7)
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%10 = load i32, i32* %9
%11 = sdiv i32 %10, 1000000000
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%14 = load i32, i32* %13
%15 = srem i32 %14, 1000000000
store i32 %15, i32* %13
%16 = call i32 @nanosleep(%struct.timespec* %5, i32* null)
ret i32 %16
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [5 x i8] c"%ld\0A\00"
define i32 @nanosleep0(i8* nocapture %0, i64 %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%6 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %5)
%7 = load i32, i32* %5
%8 = sdiv i32 %7, 1000000000
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i32 %8, i32* %9
%10 = srem i32 %7, 1000000000
store i32 %10, i32* %5
%11 = call i32 @nanosleep(%struct.timespec* %3, i32* null)
ret i32 %11
}