#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_usec;
  scalar_t__ tv_sec;
};
struct timespec {
  int tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ select(int /*<<< orphan*/, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          struct timeval *);
int main() {
  struct timespec ts;
  struct timeval te;
  int i;
  for (i = 0; i < 10; i++) {
    ts.tv_sec = 0;
    ts.tv_nsec = 10000000;
    nanosleep(&ts, NULL);
    te.tv_sec = 0;
    te.tv_usec = 40000;
    select(0, NULL, NULL, NULL, &te);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jge    118e <main+0x6e>
movq   $0x0,-0x10(%rbp)
movl   $0x989680,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
movq   $0x0,-0x20(%rbp)
movl   $0x9c40,-0x28(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x28(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1040 <select@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movq   $0x0,0x20(%rsp)
movl   $0x989680,0x18(%rsp)
lea    0x18(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
movq   $0x0,0x10(%rsp)
movl   $0x9c40,0x8(%rsp)
lea    0x8(%rsp),%r14
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
movq   $0x0,0x20(%rsp)
movl   $0x989680,0x18(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
movq   $0x0,0x10(%rsp)
movl   $0x9c40,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
movq   $0x0,0x20(%rsp)
movl   $0x989680,0x18(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
movq   $0x0,0x10(%rsp)
movl   $0x9c40,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
movq   $0x0,0x20(%rsp)
movl   $0x989680,0x18(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
movq   $0x0,0x10(%rsp)
movl   $0x9c40,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
movq   $0x0,0x20(%rsp)
movl   $0x989680,0x18(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
movq   $0x0,0x10(%rsp)
movl   $0x9c40,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
movq   $0x0,0x20(%rsp)
movl   $0x989680,0x18(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
movq   $0x0,0x10(%rsp)
movl   $0x9c40,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
movq   $0x0,0x20(%rsp)
movl   $0x989680,0x18(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
movq   $0x0,0x10(%rsp)
movl   $0x9c40,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
movq   $0x0,0x20(%rsp)
movl   $0x989680,0x18(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
movq   $0x0,0x10(%rsp)
movl   $0x9c40,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
movq   $0x0,0x20(%rsp)
movl   $0x989680,0x18(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
movq   $0x0,0x10(%rsp)
movl   $0x9c40,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
movq   $0x0,0x20(%rsp)
movl   $0x989680,0x18(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
movq   $0x0,0x10(%rsp)
movl   $0x9c40,0x8(%rsp)
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r14,%r8
call   1040 <select@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
%struct.timeval = type { i32, i64 }
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca %struct.timeval
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
br label %5
5: ; preds = %15, %0
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %18
8: ; preds = %5
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 10000000, i32* %10
%11 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i64 0, i64* %12
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i32 40000, i32* %13
%14 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %3)
br label %15
15: ; preds = %8
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %5
18: ; preds = %5
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
%struct.timeval = type { i32, i64 }
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timeval
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i64 0, i64* %5
store i32 10000000, i32* %6
%9 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
store i64 0, i64* %7
store i32 40000, i32* %8
%10 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
store i64 0, i64* %5
store i32 10000000, i32* %6
%11 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
store i64 0, i64* %7
store i32 40000, i32* %8
%12 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
store i64 0, i64* %5
store i32 10000000, i32* %6
%13 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
store i64 0, i64* %7
store i32 40000, i32* %8
%14 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
store i64 0, i64* %5
store i32 10000000, i32* %6
%15 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
store i64 0, i64* %7
store i32 40000, i32* %8
%16 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
store i64 0, i64* %5
store i32 10000000, i32* %6
%17 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
store i64 0, i64* %7
store i32 40000, i32* %8
%18 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
store i64 0, i64* %5
store i32 10000000, i32* %6
%19 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
store i64 0, i64* %7
store i32 40000, i32* %8
%20 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
store i64 0, i64* %5
store i32 10000000, i32* %6
%21 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
store i64 0, i64* %7
store i32 40000, i32* %8
%22 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
store i64 0, i64* %5
store i32 10000000, i32* %6
%23 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
store i64 0, i64* %7
store i32 40000, i32* %8
%24 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
store i64 0, i64* %5
store i32 10000000, i32* %6
%25 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
store i64 0, i64* %7
store i32 40000, i32* %8
%26 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
store i64 0, i64* %5
store i32 10000000, i32* %6
%27 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
store i64 0, i64* %7
store i32 40000, i32* %8
%28 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
ret i32 0
}