#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 dummy;
};

/* Variables and functions */
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ clock_gettime(int, struct timespec *);
char *clockstring(int);
scalar_t__ consistency_test(int, int);
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
int ksft_exit_fail();
int ksft_exit_pass();
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setbuf(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int clockid, opt;
  int userclock = 0;
  int maxclocks = 12;
  int runtime = 10;
  struct timespec ts;
  while ((opt = getopt(argc, argv, "t:c:")) != -1) {
    switch (opt) {
    case 't':
      runtime = atoi(optarg);
      break;
    case 'c':
      userclock = atoi(optarg);
      maxclocks = userclock + 1;
      break;
    default:
      printf("Usage: %s [-t <secs>] [-c <clockid>]\n", argv[0]);
      printf("	-t: Number of seconds to run\n");
      printf("	-c: clockid to use (default, all clockids)\n");
      exit(-1);
    }
  }
  setbuf(stdout, NULL);
  for (clockid = userclock; clockid < maxclocks; clockid++) {
    if (clockid == 10)
      continue;
    if (!clock_gettime(clockid, &ts)) {
      printf("Consistent %-30s ", clockstring(clockid));
      if (consistency_test(clockid, runtime))
        return ksft_exit_fail();
    }
  }
  return ksft_exit_pass();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0xc,-0x20(%rbp)
movl   $0xa,-0x24(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe27(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1284 <main+0xe4>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x63,%eax
je     1225 <main+0x85>
jmp    11fe <main+0x5e>
mov    -0x2c(%rbp),%eax
sub    $0x74,%eax
jne    1244 <main+0xa4>
jmp    120f <main+0x6f>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    127f <main+0xdf>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    127f <main+0xdf>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
jmp    11cb <main+0x2b>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <setbuf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1321 <main+0x181>
cmpl   $0xa,-0x14(%rbp)
jne    12b7 <main+0x117>
jmp    1313 <main+0x173>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%eax
jne    130e <main+0x16e>
mov    -0x14(%rbp),%edi
call   1040 <clockstring@plt>
mov    %rax,%rsi
lea    0xd99(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x24(%rbp),%esi
call   10b0 <consistency_test@plt>
cmp    $0x0,%rax
je     1309 <main+0x169>
mov    $0x0,%al
call   1060 <ksft_exit_fail@plt>
mov    %eax,-0x4(%rbp)
jmp    132b <main+0x18b>
jmp    130e <main+0x16e>
jmp    1313 <main+0x173>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    129c <main+0xfc>
mov    $0x0,%al
call   1050 <ksft_exit_pass@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%ebx
mov    $0xa,%r14d
movl   $0xc,0xc(%rsp)
xor    %ebp,%ebp
lea    0xe26(%rip),%r12
mov    0x2e17(%rip),%r13
jmp    11fc <main+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%r13),%edi
call   10b0 <atoi@plt>
mov    %eax,%r14d
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   10a0 <getopt@plt>
cmp    $0x74,%eax
je     11f0 <main+0x40>
cmp    $0xffffffff,%eax
je     1230 <main+0x80>
cmp    $0x63,%eax
jne    12bc <main+0x10c>
mov    0x0(%r13),%edi
call   10b0 <atoi@plt>
mov    %eax,%ebp
add    $0x1,%eax
mov    %eax,0xc(%rsp)
jmp    11fc <main+0x4c>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1080 <setbuf@plt>
mov    0xc(%rsp),%ebx
cmp    %ebx,%ebp
jge    12a6 <main+0xf6>
lea    0x10(%rsp),%r12
lea    0xdd7(%rip),%r15
jmp    1267 <main+0xb7>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %ebp,%ebx
je     12a6 <main+0xf6>
cmp    $0xa,%ebp
je     1260 <main+0xb0>
mov    %ebp,%edi
mov    %r12,%rsi
call   1040 <clock_gettime@plt>
test   %eax,%eax
jne    1260 <main+0xb0>
mov    %ebp,%edi
call   1050 <clockstring@plt>
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %ebp,%edi
mov    %r14d,%esi
call   10c0 <consistency_test@plt>
test   %rax,%rax
je     1260 <main+0xb0>
xor    %eax,%eax
call   1070 <ksft_exit_fail@plt>
jmp    12ad <main+0xfd>
xor    %eax,%eax
call   1060 <ksft_exit_pass@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%rsi
lea    0xd3f(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xd69(%rip),%rdi
call   1030 <puts@plt>
lea    0xd7b(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [5 x i8] c"t:c:\00"
@optarg = global i32 0
@.str.1 = [38 x i8] c"Usage: %s [-t <secs>] [-c <clockid>]\0A\00"
@.str.2 = [31 x i8] c"\09-t: Number of seconds to run\0A\00"
@.str.3 = [45 x i8] c"\09-c: clockid to use (default, all clockids)\0A\00"
@stdout = global i32 0
@.str.4 = [18 x i8] c"Consistent %-30s \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.timespec
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 12, i32* %9
store i32 10, i32* %10
br label %12
12: ; preds = %35, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %7
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %36
17: ; preds = %12
%18 = load i32, i32* %7
switch i32 %18, label %27 [
i32 116, label %19
i32 99, label %22
]
19: ; preds = %17
%20 = load i32, i32* @optarg
%21 = call i32 @atoi(i32 %20)
store i32 %21, i32* %10
br label %35
22: ; preds = %17
%23 = load i32, i32* @optarg
%24 = call i32 @atoi(i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
store i32 %26, i32* %9
br label %35
27: ; preds = %17
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %22, %19
br label %12
36: ; preds = %12
%37 = load i32, i32* @stdout
%38 = call i32 @setbuf(i32 %37, i32* null)
%39 = load i32, i32* %8
store i32 %39, i32* %6
br label %40
40: ; preds = %64, %36
%41 = load i32, i32* %6
%42 = load i32, i32* %9
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %67
44: ; preds = %40
%45 = load i32, i32* %6
%46 = icmp eq i32 %45, 10
br i1 %46, label %47, label %48
47: ; preds = %44
br label %64
48: ; preds = %44
%49 = load i32, i32* %6
%50 = call i32 @clock_gettime(i32 %49, %struct.timespec* %11)
%51 = icmp ne i32 %50, 0
br i1 %51, label %63, label %52
52: ; preds = %48
%53 = load i32, i32* %6
%54 = call i8* @clockstring(i32 %53)
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %54)
%56 = load i32, i32* %6
%57 = load i32, i32* %10
%58 = call i64 @consistency_test(i32 %56, i32 %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %52
%61 = call i32 (...) @ksft_exit_fail()
store i32 %61, i32* %3
br label %69
62: ; preds = %52
br label %63
63: ; preds = %62, %48
br label %64
64: ; preds = %63, %47
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %40
67: ; preds = %40
%68 = call i32 (...) @ksft_exit_pass()
store i32 %68, i32* %3
br label %69
69: ; preds = %67, %60
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@.str = [5 x i8] c"t:c:\00"
@optarg = global i32 0
@.str.1 = [38 x i8] c"Usage: %s [-t <secs>] [-c <clockid>]\0A\00"
@stdout = global i32 0
@.str.4 = [18 x i8] c"Consistent %-30s \00"
@str = [30 x i8] c"\09-t: Number of seconds to run\00"
@str.5 = [44 x i8] c"\09-c: clockid to use (default, all clockids)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
br label %5
5: ; preds = %15, %2
%6 = phi i32 [ %17, %15 ], [ 0, %2 ]
%7 = phi i32 [ %18, %15 ], [ 12, %2 ]
%8 = phi i32 [ %10, %15 ], [ 10, %2 ]
br label %9
9: ; preds = %5, %12
%10 = phi i32 [ %14, %12 ], [ %8, %5 ]
%11 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %11, label %19 [
i32 -1, label %25
i32 116, label %12
i32 99, label %15
]
12: ; preds = %9
%13 = load i32, i32* @optarg
%14 = tail call i32 @atoi(i32 %13)
br label %9
15: ; preds = %9
%16 = load i32, i32* @optarg
%17 = tail call i32 @atoi(i32 %16)
%18 = add nsw i32 %17, 1
br label %5
19: ; preds = %9
%20 = load i8*, i8** %1
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str, i64 0, i64 0))
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.5, i64 0, i64 0))
%24 = tail call i32 @exit(i32 -1)
unreachable
25: ; preds = %9
%26 = load i32, i32* @stdout
%27 = tail call i32 @setbuf(i32 %26, i32* null)
%28 = icmp slt i32 %6, %7
br i1 %28, label %29, label %45
29: ; preds = %25, %42
%30 = phi i32 [ %43, %42 ], [ %6, %25 ]
%31 = icmp eq i32 %30, 10
br i1 %31, label %42, label %32
32: ; preds = %29
%33 = call i32 @clock_gettime(i32 %30, %struct.timespec* %3)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = call i8* @clockstring(i32 %30)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = call i64 @consistency_test(i32 %30, i32 %10)
%39 = icmp eq i64 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %35
%41 = call i32 (...) @ksft_exit_fail()
br label %47
42: ; preds = %32, %35, %29
%43 = add i32 %30, 1
%44 = icmp eq i32 %43, %7
br i1 %44, label %45, label %29
45: ; preds = %42, %25
%46 = call i32 (...) @ksft_exit_pass()
br label %47
47: ; preds = %45, %40
%48 = phi i32 [ %41, %40 ], [ %46, %45 ]
ret i32 %48
}