#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 tv_sec;
  int tv_nsec;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int clock_getres(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char **);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int /*<<< orphan*/);
int main(void) {
  struct timespec res;
  int clock_return = clock_getres(CLOCK_MONOTONIC, &res);
  char clocksource[50];
  char line[80];
  FILE *fr;
  if ((fr = fopen(
           "/sys/devices/system/clocksource/clocksource0/current_clocksource",
           "rt")) == NULL) {
    perror("fopen");
    return EXIT_FAILURE;
  }
  while (fgets(line, 80, fr) != NULL) {
    sscanf(line, "%s", &clocksource);
  }
  fclose(fr);
  if (!strncmp(clocksource, "kvm-clock", strlen("kvm-clock"))) {
    if (clock_return == 0) {
      if (res.tv_sec > 1 || res.tv_nsec > 100) {
        printf("FAIL: clock_getres returned bad clock resolution\n");
        return EXIT_FAILURE;
      } else {
        printf("PASS: check successful\n");
        return EXIT_SUCCESS;
      }
    } else {
      printf("FAIL: clock_getres failed\n");
      return EXIT_FAILURE;
    }
  } else {
    printf("FAIL: invalid clock source: %s\n", clocksource);
    return EXIT_FAILURE;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1080 <clock_getres@plt>
mov    %eax,-0x14(%rbp)
lea    0xe42(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0xa8(%rbp)
cmp    $0x0,%rax
jne    11f8 <main+0x68>
lea    0xe62(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1315 <main+0x185>
jmp    11fd <main+0x6d>
lea    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rdx
mov    $0x50,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     123b <main+0xab>
lea    -0xa0(%rbp),%rdi
lea    -0x50(%rbp),%rdx
lea    0xe19(%rip),%rsi
call   1090 <sscanf@plt>
jmp    11fd <main+0x6d>
mov    -0xa8(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    0xdf4(%rip),%rdi
call   1050 <strlen@plt>
mov    -0xb0(%rbp),%rdi
mov    %eax,%edx
lea    0xddf(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12f7 <main+0x167>
cmpl   $0x0,-0x14(%rbp)
jne    12d8 <main+0x148>
cmpl   $0x1,-0x10(%rbp)
jg     129a <main+0x10a>
cmpl   $0x64,-0xc(%rbp)
jle    12b9 <main+0x129>
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1315 <main+0x185>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2d02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1315 <main+0x185>
lea    0xdc2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1315 <main+0x185>
lea    -0x50(%rbp),%rsi
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xa0,%rsp
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1090 <clock_getres@plt>
mov    %eax,%r14d
lea    0xe34(%rip),%rdi
lea    0xe6e(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12b6 <main+0x116>
mov    %rax,%rbx
lea    0x50(%rsp),%rdi
mov    $0x50,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1233 <main+0x93>
lea    0xe48(%rip),%r15
lea    0x50(%rsp),%rbp
lea    0x10(%rsp),%r12
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   10a0 <sscanf@plt>
mov    %rbp,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
jne    1210 <main+0x70>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe0b(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1272 <main+0xd2>
lea    0xdf3(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12c2 <main+0x122>
test   %r14d,%r14d
je     1285 <main+0xe5>
lea    0xdf9(%rip),%rdi
call   1040 <puts@plt>
jmp    12c2 <main+0x122>
cmpl   $0x1,0x8(%rsp)
jg     12a8 <main+0x108>
cmpl   $0x65,0xc(%rsp)
jge    12a8 <main+0x108>
lea    0xdf7(%rip),%rdi
call   1040 <puts@plt>
mov    0x2d2a(%rip),%rax
jmp    12c9 <main+0x129>
lea    0xdf9(%rip),%rdi
call   1040 <puts@plt>
jmp    12c2 <main+0x122>
lea    0xd87(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [65 x i8] c"/sys/devices/system/clocksource/clocksource0/current_clocksource\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [6 x i8] c"fopen\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [10 x i8] c"kvm-clock\00"
@.str.5 = [50 x i8] c"FAIL: clock_getres returned bad clock resolution\0A\00"
@.str.6 = [24 x i8] c"PASS: check successful\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.7 = [27 x i8] c"FAIL: clock_getres failed\0A\00"
@.str.8 = [32 x i8] c"FAIL: invalid clock source: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca i32
%4 = alloca [50 x i8]
%5 = alloca [80 x i8]
%6 = alloca i32*
store i32 0, i32* %1
%7 = load i32, i32* @CLOCK_MONOTONIC
%8 = call i32 @clock_getres(i32 %7, %struct.timespec* %2)
store i32 %8, i32* %3
%9 = call i32* @fopen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
store i32 %13, i32* %1
br label %55
14: ; preds = %0
br label %15
15: ; preds = %20, %14
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%17 = load i32*, i32** %6
%18 = call i32* @fgets(i8* %16, i32 80, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%22 = bitcast [50 x i8]* %4 to i8**
%23 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %22)
br label %15
24: ; preds = %15
%25 = load i32*, i32** %6
%26 = call i32 @fclose(i32* %25)
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%28 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @strncmp(i8* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %51, label %31
31: ; preds = %24
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %48
34: ; preds = %31
%35 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%36 = load i32, i32* %35
%37 = icmp sgt i32 %36, 1
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%40 = load i32, i32* %39
%41 = icmp sgt i32 %40, 100
br i1 %41, label %42, label %45
42: ; preds = %38, %34
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %1
br label %55
45: ; preds = %38
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%47 = load i32, i32* @EXIT_SUCCESS
store i32 %47, i32* %1
br label %55
48: ; preds = %31
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.7, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
store i32 %50, i32* %1
br label %55
51: ; preds = %24
%52 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* %52)
%54 = load i32, i32* @EXIT_FAILURE
store i32 %54, i32* %1
br label %55
55: ; preds = %51, %48, %45, %42, %11
%56 = load i32, i32* %1
ret i32 %56
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [65 x i8] c"/sys/devices/system/clocksource/clocksource0/current_clocksource\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [6 x i8] c"fopen\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [10 x i8] c"kvm-clock\00"
@EXIT_SUCCESS = global i32 0
@.str.8 = [32 x i8] c"FAIL: invalid clock source: %s\0A\00"
@str = [26 x i8] c"FAIL: clock_getres failed\00"
@str.9 = [23 x i8] c"PASS: check successful\00"
@str.10 = [49 x i8] c"FAIL: clock_getres returned bad clock resolution\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca [50 x i8]
%3 = alloca [80 x i8]
%4 = bitcast %struct.timespec* %1 to i8*
%5 = load i32, i32* @CLOCK_MONOTONIC
%6 = call i32 @clock_getres(i32 %5, %struct.timespec* %1)
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%9 = call i32* @fopen(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %16, label %11
11: ; preds = %0
%12 = call i32* @fgets(i8* %8, i32 80, i32* %9)
%13 = icmp eq i32* %12, null
br i1 %13, label %22, label %14
14: ; preds = %11
%15 = bitcast [50 x i8]* %2 to i8**
br label %18
16: ; preds = %0
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %45
18: ; preds = %14, %18
%19 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %15)
%20 = call i32* @fgets(i8* %8, i32 80, i32* %9)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %18
22: ; preds = %18, %11
%23 = call i32 @fclose(i32* %9)
%24 = call i32 @strlen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%25 = call i32 @strncmp(i8* %7, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %43
27: ; preds = %22
%28 = icmp eq i32 %6, 0
br i1 %28, label %29, label %41
29: ; preds = %27
%30 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%31 = load i32, i32* %30
%32 = icmp sgt i32 %31, 1
%33 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%34 = load i32, i32* %33
%35 = icmp sgt i32 %34, 100
%36 = select i1 %32, i1 true, i1 %35
br i1 %36, label %37, label %39
37: ; preds = %29
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.10, i64 0, i64 0))
br label %45
39: ; preds = %29
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.9, i64 0, i64 0))
br label %45
41: ; preds = %27
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %45
43: ; preds = %22
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* %7)
br label %45
45: ; preds = %43, %41, %39, %37, %16
%46 = phi i32* [ @EXIT_FAILURE, %16 ], [ @EXIT_FAILURE, %43 ], [ @EXIT_FAILURE, %37 ], [ @EXIT_SUCCESS, %39 ], [ @EXIT_FAILURE, %41 ]
%47 = load i32, i32* %46
ret i32 %47
}