#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 */
typedef int time_t;
struct timespec {
  int tv_sec;
  long tv_nsec;
};

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ debug(char *);
int /*<<< orphan*/ mafunc(int);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int main() {
  int i = 0;
  debug("hello i m in main an i will wait 4 microsec\n");
  do {
    struct timespec tm;
    tm.tv_sec = (time_t)4 / 1000;
    tm.tv_nsec = (long)(4 % 1000) * 1000;
    nanosleep(&tm, NULL);
  } while (0);
  for (i = 0; i < 4; i++) {
    mafunc(i);
    debug("main sleep 1 microsec\n");
    do {
      struct timespec tm;
      tm.tv_sec = (time_t)1 / 1000;
      tm.tv_nsec = (long)(1 % 1000) * 1000;
      nanosleep(&tm, NULL);
    } while (0);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xeb3(%rip),%rdi
call   1030 <debug@plt>
movl   $0x0,-0x18(%rbp)
movq   $0xfa0,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11c2 <main+0x92>
mov    -0x8(%rbp),%edi
call   1050 <mafunc@plt>
lea    0xe9f(%rip),%rdi
call   1030 <debug@plt>
movl   $0x0,-0x28(%rbp)
movq   $0x3e8,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
jmp    11b4 <main+0x84>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1175 <main+0x45>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0xec2(%rip),%rdi
call   1030 <debug@plt>
movl   $0x0,0x8(%rsp)
movq   $0xfa0,0x10(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
xor    %edi,%edi
call   1050 <mafunc@plt>
lea    0xebf(%rip),%r14
mov    %r14,%rdi
call   1030 <debug@plt>
movl   $0x0,0x8(%rsp)
movq   $0x3e8,0x10(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    $0x1,%edi
call   1050 <mafunc@plt>
mov    %r14,%rdi
call   1030 <debug@plt>
movl   $0x0,0x8(%rsp)
movq   $0x3e8,0x10(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    $0x2,%edi
call   1050 <mafunc@plt>
mov    %r14,%rdi
call   1030 <debug@plt>
movl   $0x0,0x8(%rsp)
movq   $0x3e8,0x10(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    $0x3,%edi
call   1050 <mafunc@plt>
mov    %r14,%rdi
call   1030 <debug@plt>
movl   $0x0,0x8(%rsp)
movq   $0x3e8,0x10(%rsp)
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [45 x i8] c"hello i m in main an i will wait 4 microsec\0A\00"
@.str.1 = [23 x i8] c"main sleep 1 microsec\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
store i32 0, i32* %1
store i32 0, i32* %2
%5 = call i32 @debug(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %0
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 0, i32* %7
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 4000, i64* %8
%9 = call i32 @nanosleep(%struct.timespec* %3, i32* null)
br label %10
10: ; preds = %6
store i32 0, i32* %2
br label %11
11: ; preds = %23, %10
%12 = load i32, i32* %2
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = load i32, i32* %2
%16 = call i32 @mafunc(i32 %15)
%17 = call i32 @debug(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %14
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 0, i32* %19
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i64 1000, i64* %20
%21 = call i32 @nanosleep(%struct.timespec* %4, i32* null)
br label %22
22: ; preds = %18
br label %23
23: ; preds = %22
%24 = load i32, i32* %2
%25 = add nsw i32 %24, 1
store i32 %25, i32* %2
br label %11
26: ; preds = %11
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@.str = [45 x i8] c"hello i m in main an i will wait 4 microsec\0A\00"
@.str.1 = [23 x i8] c"main sleep 1 microsec\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = tail call i32 @debug(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%4 = bitcast %struct.timespec* %1 to i8*
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 0, i32* %5
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i64 4000, i64* %6
%7 = call i32 @nanosleep(%struct.timespec* %1, i32* null)
%8 = bitcast %struct.timespec* %2 to i8*
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%11 = call i32 @mafunc(i32 0)
%12 = call i32 @debug(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %9
store i64 1000, i64* %10
%13 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%14 = call i32 @mafunc(i32 1)
%15 = call i32 @debug(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %9
store i64 1000, i64* %10
%16 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%17 = call i32 @mafunc(i32 2)
%18 = call i32 @debug(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %9
store i64 1000, i64* %10
%19 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%20 = call i32 @mafunc(i32 3)
%21 = call i32 @debug(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %9
store i64 1000, i64* %10
%22 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}