#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_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("Nanosleep %-31s ", clockstring(clockid));
    length = 10;
    while (length <= (1000000000ULL * 10)) {
      ret = nanosleep_test(clockid, length);
      if (ret == 0xf00f) {
        printf("[UNSUPPORTED]\n");
        goto next;
      }
      if (ret < 0) {
        printf("[FAILED]\n");
        return ksft_exit_fail();
      }
      length *= 100;
    }
    printf("[OK]\n");
  next:
    ret = 0;
  }
  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    1256 <main+0x106>
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    1248 <main+0xf8>
mov    -0x1c(%rbp),%edi
call   1040 <clockstring@plt>
mov    %rax,%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movq   $0xa,-0x18(%rbp)
movabs $0x2540be400,%rax
cmp    %rax,-0x18(%rbp)
ja     1233 <main+0xe3>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <nanosleep_test@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xf00f,-0x20(%rbp)
jne    11fe <main+0xae>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1241 <main+0xf1>
cmpl   $0x0,-0x20(%rbp)
jge    1225 <main+0xd5>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1060 <ksft_exit_fail@plt>
mov    %eax,-0x4(%rbp)
jmp    1260 <main+0x110>
imul   $0x64,-0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11bb <main+0x6b>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116d <main+0x1d>
mov    $0x0,%al
call   1050 <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),%r14
lea    0xeaa(%rip),%rbx
lea    0xe95(%rip),%r15
xor    %ebp,%ebp
jmp    1191 <main+0x31>
call   1040 <puts@plt>
add    $0x1,%ebp
cmp    $0xc,%ebp
je     1264 <main+0x104>
cmp    $0xa,%ebp
je     1185 <main+0x25>
mov    %ebp,%eax
and    $0x7ffffffe,%eax
cmp    $0x2,%eax
je     1185 <main+0x25>
mov    %ebp,%edi
call   1050 <clockstring@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    $0xa,%esi
mov    %ebp,%edi
call   1030 <nanosleep_test@plt>
mov    %rbx,%rdi
cmp    $0xf00f,%eax
je     1180 <main+0x20>
test   %eax,%eax
js     1247 <main+0xe7>
mov    $0x3e8,%esi
mov    %ebp,%edi
call   1030 <nanosleep_test@plt>
mov    %rbx,%rdi
cmp    $0xf00f,%eax
je     1180 <main+0x20>
test   %eax,%eax
js     1247 <main+0xe7>
mov    $0x186a0,%esi
mov    %ebp,%edi
call   1030 <nanosleep_test@plt>
mov    %rbx,%rdi
cmp    $0xf00f,%eax
je     1180 <main+0x20>
test   %eax,%eax
js     1247 <main+0xe7>
mov    $0x989680,%esi
mov    %ebp,%edi
call   1030 <nanosleep_test@plt>
mov    %rbx,%rdi
cmp    $0xf00f,%eax
je     1180 <main+0x20>
test   %eax,%eax
js     1247 <main+0xe7>
mov    $0x3b9aca00,%esi
mov    %ebp,%edi
call   1030 <nanosleep_test@plt>
mov    %rbx,%rdi
cmp    $0xf00f,%eax
je     1180 <main+0x20>
mov    %r15,%rdi
test   %eax,%eax
jns    1180 <main+0x20>
lea    0xdc8(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <ksft_exit_fail@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <ksft_exit_pass@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Nanosleep %-31s \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 = %49, %2
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 12
br i1 %11, label %12, label %52
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 %49
22: ; preds = %18
%23 = load i32, i32* %7
%24 = call i8* @clockstring(i32 %23)
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %24)
store i64 10, i64* %6
br label %26
26: ; preds = %43, %22
%27 = load i64, i64* %6
%28 = icmp ule i64 %27, 10000000000
br i1 %28, label %29, label %46
29: ; preds = %26
%30 = load i32, i32* %7
%31 = load i64, i64* %6
%32 = call i32 @nanosleep_test(i32 %30, i64 %31)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 61455
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %48
37: ; preds = %29
%38 = load i32, i32* %8
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 (...) @ksft_exit_fail()
store i32 %42, i32* %3
br label %54
43: ; preds = %37
%44 = load i64, i64* %6
%45 = mul nsw i64 %44, 100
store i64 %45, i64* %6
br label %26
46: ; preds = %26
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %46, %35
store i32 0, i32* %8
br label %49
49: ; preds = %48, %21
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %9
52: ; preds = %9
%53 = call i32 (...) @ksft_exit_pass()
store i32 %53, i32* %3
br label %54
54: ; preds = %52, %40
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [17 x i8] c"Nanosleep %-31s \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, %42
%4 = phi i32 [ 0, %2 ], [ %43, %42 ]
%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 %42, label %9
9: ; preds = %3
%10 = tail call i8* @clockstring(i32 %4)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @nanosleep_test(i32 %4, i64 10)
%13 = icmp eq i32 %12, 61455
br i1 %13, label %39, label %14
14: ; preds = %9
%15 = icmp slt i32 %12, 0
br i1 %15, label %16, label %19
16: ; preds = %37, %32, %27, %22, %14
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.4, i64 0, i64 0))
%18 = tail call i32 (...) @ksft_exit_fail()
br label %47
19: ; preds = %14
%20 = tail call i32 @nanosleep_test(i32 %4, i64 1000)
%21 = icmp eq i32 %20, 61455
br i1 %21, label %39, label %22
22: ; preds = %19
%23 = icmp slt i32 %20, 0
br i1 %23, label %16, label %24
24: ; preds = %22
%25 = tail call i32 @nanosleep_test(i32 %4, i64 100000)
%26 = icmp eq i32 %25, 61455
br i1 %26, label %39, label %27
27: ; preds = %24
%28 = icmp slt i32 %25, 0
br i1 %28, label %16, label %29
29: ; preds = %27
%30 = tail call i32 @nanosleep_test(i32 %4, i64 10000000)
%31 = icmp eq i32 %30, 61455
br i1 %31, label %39, label %32
32: ; preds = %29
%33 = icmp slt i32 %30, 0
br i1 %33, label %16, label %34
34: ; preds = %32
%35 = tail call i32 @nanosleep_test(i32 %4, i64 1000000000)
%36 = icmp eq i32 %35, 61455
br i1 %36, label %39, label %37
37: ; preds = %34
%38 = icmp slt i32 %35, 0
br i1 %38, label %16, label %39
39: ; preds = %37, %9, %19, %24, %29, %34
%40 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0), %34 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0), %29 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0), %24 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0), %19 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0), %9 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0), %37 ]
%41 = tail call i32 @puts(i8* dereferenceable(1) %40)
br label %42
42: ; preds = %39, %3
%43 = add nuw nsw i32 %4, 1
%44 = icmp eq i32 %43, 12
br i1 %44, label %45, label %3
45: ; preds = %42
%46 = tail call i32 (...) @ksft_exit_pass()
br label %47
47: ; preds = %45, %16
%48 = phi i32 [ %18, %16 ], [ %46, %45 ]
ret i32 %48
}