#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 */

/* Variables and functions */
char *clockstring(int);
int ksft_exit_fail();
int ksft_exit_pass();
int nanosleep_lat_test(int, long long);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  long long length;
  int clockid, ret;
  for (clockid = 0; clockid < 12; clockid++) {
    if (clockid == 2 || clockid == 3 || clockid == 10) {
      continue;
    }
    printf("nsleep latency %-26s ", clockstring(clockid));
    length = 10;
    while (length <= (1000000000ULL * 10)) {
      ret = nanosleep_lat_test(clockid, length);
      if (ret) {
        break;
      }
      length *= 100;
    }
    if (ret == 0xf00f) {
      printf("[UNSUPPORTED]\n");
      continue;
    }
    if (ret < 0) {
      printf("[FAILED]\n");
      return ksft_exit_fail();
    }
    printf("[OK]\n");
  }
  return ksft_exit_pass();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xc,-0x1c(%rbp)
jge    125e <main+0x10e>
cmpl   $0x2,-0x1c(%rbp)
je     1195 <main+0x45>
cmpl   $0x3,-0x1c(%rbp)
je     1195 <main+0x45>
cmpl   $0xa,-0x1c(%rbp)
jne    119a <main+0x4a>
jmp    1250 <main+0x100>
mov    -0x1c(%rbp),%edi
call   1030 <clockstring@plt>
mov    %rax,%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0xa,-0x18(%rbp)
movabs $0x2540be400,%rax
cmp    %rax,-0x18(%rbp)
ja     11fb <main+0xab>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1070 <nanosleep_lat_test@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11ed <main+0x9d>
jmp    11fb <main+0xab>
imul   $0x64,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11bb <main+0x6b>
cmpl   $0xf00f,-0x20(%rbp)
jne    121b <main+0xcb>
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1250 <main+0x100>
cmpl   $0x0,-0x20(%rbp)
jge    1242 <main+0xf2>
lea    0xdf9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1050 <ksft_exit_fail@plt>
mov    %eax,-0x4(%rbp)
jmp    1268 <main+0x118>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116d <main+0x1d>
mov    $0x0,%al
call   1040 <ksft_exit_pass@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe92(%rip),%r15
lea    0xea1(%rip),%r14
lea    0xea8(%rip),%rbx
xor    %ebp,%ebp
jmp    1191 <main+0x31>
call   1030 <puts@plt>
add    $0x1,%ebp
cmp    $0xc,%ebp
je     1246 <main+0xe6>
cmp    $0xa,%ebp
je     1185 <main+0x25>
mov    %ebp,%eax
and    $0x7ffffffe,%eax
cmp    $0x2,%eax
je     1185 <main+0x25>
mov    %ebp,%edi
call   1040 <clockstring@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xa,%esi
mov    %ebp,%edi
call   1080 <nanosleep_lat_test@plt>
test   %eax,%eax
jne    1210 <main+0xb0>
mov    $0x3e8,%esi
mov    %ebp,%edi
call   1080 <nanosleep_lat_test@plt>
test   %eax,%eax
jne    1210 <main+0xb0>
mov    $0x186a0,%esi
mov    %ebp,%edi
call   1080 <nanosleep_lat_test@plt>
test   %eax,%eax
jne    1210 <main+0xb0>
mov    $0x989680,%esi
mov    %ebp,%edi
call   1080 <nanosleep_lat_test@plt>
test   %eax,%eax
jne    1210 <main+0xb0>
mov    $0x3b9aca00,%esi
mov    %ebp,%edi
call   1080 <nanosleep_lat_test@plt>
mov    %r14,%rdi
test   %eax,%eax
je     1180 <main+0x20>
nopl   (%rax)
mov    %rbx,%rdi
cmp    $0xf00f,%eax
je     1180 <main+0x20>
mov    %r14,%rdi
test   %eax,%eax
jns    1180 <main+0x20>
lea    0xdeb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <ksft_exit_fail@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <ksft_exit_pass@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"nsleep latency %-26s \00"
@.str.1 = [15 x i8] c"[UNSUPPORTED]\0A\00"
@.str.2 = [10 x i8] c"[FAILED]\0A\00"
@.str.3 = [6 x i8] c"[OK]\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
br label %9
9: ; preds = %52, %2
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 12
br i1 %11, label %12, label %55
12: ; preds = %9
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, 2
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 3
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %22
21: ; preds = %18, %15, %12
br label %52
22: ; preds = %18
%23 = load i32, i32* %7
%24 = call i8* @clockstring(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %24)
store i64 10, i64* %6
br label %26
26: ; preds = %36, %22
%27 = load i64, i64* %6
%28 = icmp ule i64 %27, 10000000000
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i32, i32* %7
%31 = load i64, i64* %6
%32 = call i32 @nanosleep_lat_test(i32 %30, i64 %31)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
br label %39
36: ; preds = %29
%37 = load i64, i64* %6
%38 = mul nsw i64 %37, 100
store i64 %38, i64* %6
br label %26
39: ; preds = %35, %26
%40 = load i32, i32* %8
%41 = icmp eq i32 %40, 61455
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %52
44: ; preds = %39
%45 = load i32, i32* %8
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%49 = call i32 (...) @ksft_exit_fail()
store i32 %49, i32* %3
br label %57
50: ; preds = %44
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %52
52: ; preds = %50, %42, %21
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %9
55: ; preds = %9
%56 = call i32 (...) @ksft_exit_pass()
store i32 %56, i32* %3
br label %57
57: ; preds = %55, %47
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@.str = [22 x i8] c"nsleep latency %-26s \00"
@str = [5 x i8] c"[OK]\00"
@str.4 = [9 x i8] c"[FAILED]\00"
@str.5 = [14 x i8] c"[UNSUPPORTED]\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %2, %37
%4 = phi i32 [ 0, %2 ], [ %38, %37 ]
%5 = and i32 %4, 2147483646
%6 = icmp eq i32 %5, 2
%7 = icmp eq i32 %4, 10
%8 = or i1 %7, %6
br i1 %8, label %37, label %9
9: ; preds = %3
%10 = tail call i8* @clockstring(i32 %4)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @nanosleep_lat_test(i32 %4, i64 10)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %9
%15 = tail call i32 @nanosleep_lat_test(i32 %4, i64 1000)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = tail call i32 @nanosleep_lat_test(i32 %4, i64 100000)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %17
%21 = tail call i32 @nanosleep_lat_test(i32 %4, i64 10000000)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = tail call i32 @nanosleep_lat_test(i32 %4, i64 1000000000)
%25 = icmp eq i32 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %23, %20, %17, %14, %9
%27 = phi i32 [ %12, %9 ], [ %15, %14 ], [ %18, %17 ], [ %21, %20 ], [ %24, %23 ]
%28 = icmp eq i32 %27, 61455
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = icmp slt i32 %27, 0
br i1 %30, label %31, label %34
31: ; preds = %29
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.4, i64 0, i64 0))
%33 = tail call i32 (...) @ksft_exit_fail()
br label %42
34: ; preds = %29, %23, %26
%35 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0), %26 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0), %23 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0), %29 ]
%36 = tail call i32 @puts(i8* dereferenceable(1) %35)
br label %37
37: ; preds = %34, %3
%38 = add nuw nsw i32 %4, 1
%39 = icmp eq i32 %38, 12
br i1 %39, label %40, label %3
40: ; preds = %37
%41 = tail call i32 (...) @ksft_exit_pass()
br label %42
42: ; preds = %40, %31
%43 = phi i32 [ %33, %31 ], [ %41, %40 ]
ret i32 %43
}