#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 timex {
  long esterror;
  int status;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int STA_UNSYNC;
int TIME_ERROR;
int adjtimex(struct timex *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int main() {
  struct timex tx = {0};
  int rc;
  long long int error;
  const char *enable_check_time = getenv("ENABLE_CHECK_TIME");
  if (enable_check_time == NULL) {
    fprintf(stderr, "ENABLE_CHECK_TIME unset. internal consistency is broken. "
                    "failing hard.\n");
    return 1;
  }
  if (strcmp(enable_check_time, "false") == 0) {
    fprintf(stderr, "Time synchronization check has been disabled. Skipping "
                    "NTP check. If clocks drift, odd bugs may appear.\n");
    return 0;
  } else if (strcmp(enable_check_time, "true") == 0) {
  } else {
    fprintf(stderr,
            "ENABLE_CHECK_TIME is something other than 'true' or 'false'. "
            "internal consistency is broken. failing hard.\n");
    return 1;
  }
  fprintf(
      stderr,
      "Checking whether time is synchronized using the kernel adjtimex API.\n");
  fprintf(stderr, "Time can be synchronized via most popular mechanisms (ntpd, "
                  "chrony, systemd-timesyncd, etc.)\n");
  rc = adjtimex(&tx);
  if (rc == -1) {
    perror("adjtimex");
    fprintf(stderr,
            "adjtimex() returned -1 indicating error. Unable to determine "
            "clock sync. See above perror message for details.\n");
    return 1;
  }
  if (rc == TIME_ERROR) {
    fprintf(stderr,
            "Time is not synchronized / marked as bad by the kernel.\n");
    return 1;
  }
  error = tx.esterror - 100L * 1000L;
  if (error > 0) {
    fprintf(stderr,
            "Clock is less stable than allowed. Max estimated error exceeded "
            "by: %lld(usec)\n",
            error);
    return 1;
  }
  if (tx.status & STA_UNSYNC) {
    fprintf(stderr, "Clock is out of sync / in unsync state. Must be "
                    "synchronized for proper operation.\n");
    return 1;
  }
  fprintf(stderr, "Time is in sync!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
lea    0xe7a(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11bd <main+0x5d>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    137f <main+0x21f>
mov    -0x30(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11fa <main+0x9a>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    137f <main+0x21f>
mov    -0x30(%rbp),%rdi
lea    0xec4(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1219 <main+0xb9>
jmp    123c <main+0xdc>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
lea    0xea5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    137f <main+0x21f>
jmp    1241 <main+0xe1>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xee9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xf18(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    -0x18(%rbp),%rdi
call   1080 <adjtimex@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12b4 <main+0x154>
lea    0xf52(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d40(%rip),%rax
mov    (%rax),%edi
lea    0xf46(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    137f <main+0x21f>
mov    -0x1c(%rbp),%eax
mov    0x2d2a(%rip),%rcx
cmp    (%rcx),%eax
jne    12e9 <main+0x189>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xf81(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    137f <main+0x21f>
mov    -0x18(%rbp),%rax
sub    $0x186a0,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jle    1329 <main+0x1c9>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xf7a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    137f <main+0x21f>
mov    -0x10(%rbp),%eax
mov    0x2c9d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1361 <main+0x201>
mov    0x2c93(%rip),%rax
mov    (%rax),%edi
lea    0xf92(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    137f <main+0x21f>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
lea    0xfc3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0xe9d(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     11aa <main+0x5a>
mov    %rax,%rbx
lea    0xee3(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11c8 <main+0x78>
lea    0xf3e(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
mov    0x2e3e(%rip),%rbx
mov    (%rbx),%edi
test   %rax,%rax
je     11e9 <main+0x99>
lea    0xf26(%rip),%rsi
jmp    11ba <main+0x6a>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebx
jmp    11e1 <main+0x91>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xf4a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xf80(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rsp,%rdi
call   1070 <adjtimex@plt>
cmp    $0xffffffff,%eax
je     127e <main+0x12e>
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%eax
jne    122a <main+0xda>
mov    (%rbx),%edi
lea    0x102f(%rip),%rsi
jmp    11ba <main+0x6a>
mov    (%rsp),%rdx
cmp    $0x186a1,%rdx
jl     1255 <main+0x105>
add    $0xfffffffffffe7960,%rdx
mov    (%rbx),%edi
lea    0x1049(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebx
jmp    11e1 <main+0x91>
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    (%rbx),%edi
test   %eax,0x8(%rsp)
je     1272 <main+0x122>
lea    0x1073(%rip),%rsi
jmp    11ba <main+0x6a>
lea    0x10bb(%rip),%rsi
jmp    11d8 <main+0x88>
lea    0xf59(%rip),%rdi
call   1060 <perror@plt>
mov    (%rbx),%edi
lea    0xf54(%rip),%rsi
jmp    11ba <main+0x6a>

LLVM IR (-O0):
%struct.timex = type { i64, i32, i32 }
@.str = [18 x i8] c"ENABLE_CHECK_TIME\00"
@stderr = global i32 0
@.str.1 = [72 x i8] c"ENABLE_CHECK_TIME unset. internal consistency is broken. failing hard.\0A\00"
@.str.2 = [6 x i8] c"false\00"
@.str.3 = [105 x i8] c"Time synchronization check has been disabled. Skipping NTP check. If clocks drift, odd bugs may appear.\0A\00"
@.str.4 = [5 x i8] c"true\00"
@.str.5 = [108 x i8] c"ENABLE_CHECK_TIME is something other than 'true' or 'false'. internal consistency is broken. failing hard.\0A\00"
@.str.6 = [70 x i8] c"Checking whether time is synchronized using the kernel adjtimex API.\0A\00"
@.str.7 = [94 x i8] c"Time can be synchronized via most popular mechanisms (ntpd, chrony, systemd-timesyncd, etc.)\0A\00"
@.str.8 = [9 x i8] c"adjtimex\00"
@.str.9 = [112 x i8] c"adjtimex() returned -1 indicating error. Unable to determine clock sync. See above perror message for details.\0A\00"
@TIME_ERROR = global i32 0
@.str.10 = [57 x i8] c"Time is not synchronized / marked as bad by the kernel.\0A\00"
@.str.11 = [80 x i8] c"Clock is less stable than allowed. Max estimated error exceeded by: %lld(usec)\0A\00"
@STA_UNSYNC = global i32 0
@.str.12 = [84 x i8] c"Clock is out of sync / in unsync state. Must be synchronized for proper operation.\0A\00"
@.str.13 = [18 x i8] c"Time is in sync!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timex
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
store i32 0, i32* %1
%6 = bitcast %struct.timex* %2 to i8*
%7 = call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %70
13: ; preds = %0
%14 = load i8*, i8** %5
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %70
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
br label %28
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([108 x i8], [108 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %1
br label %70
28: ; preds = %24
br label %29
29: ; preds = %28
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.6, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.7, i64 0, i64 0))
%34 = call i32 @adjtimex(%struct.timex* %2)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %41
37: ; preds = %29
%38 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([112 x i8], [112 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %1
br label %70
41: ; preds = %29
%42 = load i32, i32* %3
%43 = load i32, i32* @TIME_ERROR
%44 = icmp eq i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %1
br label %70
48: ; preds = %41
%49 = getelementptr inbounds %struct.timex, %struct.timex* %2, i32 0, i32 0
%50 = load i64, i64* %49
%51 = sub nsw i64 %50, 100000
store i64 %51, i64* %4
%52 = load i64, i64* %4
%53 = icmp sgt i64 %52, 0
br i1 %53, label %54, label %58
54: ; preds = %48
%55 = load i32, i32* @stderr
%56 = load i64, i64* %4
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.11, i64 0, i64 0), i64 %56)
store i32 1, i32* %1
br label %70
58: ; preds = %48
%59 = getelementptr inbounds %struct.timex, %struct.timex* %2, i32 0, i32 1
%60 = load i32, i32* %59
%61 = load i32, i32* @STA_UNSYNC
%62 = and i32 %60, %61
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %58
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %1
br label %70
67: ; preds = %58
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %1
br label %70
70: ; preds = %67, %64, %54, %45, %37, %25, %17, %10
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
%struct.timex = type { i64, i32, i32 }
@.str = [18 x i8] c"ENABLE_CHECK_TIME\00"
@stderr = global i32 0
@.str.1 = [72 x i8] c"ENABLE_CHECK_TIME unset. internal consistency is broken. failing hard.\0A\00"
@.str.2 = [6 x i8] c"false\00"
@.str.3 = [105 x i8] c"Time synchronization check has been disabled. Skipping NTP check. If clocks drift, odd bugs may appear.\0A\00"
@.str.4 = [5 x i8] c"true\00"
@.str.5 = [108 x i8] c"ENABLE_CHECK_TIME is something other than 'true' or 'false'. internal consistency is broken. failing hard.\0A\00"
@.str.6 = [70 x i8] c"Checking whether time is synchronized using the kernel adjtimex API.\0A\00"
@.str.7 = [94 x i8] c"Time can be synchronized via most popular mechanisms (ntpd, chrony, systemd-timesyncd, etc.)\0A\00"
@.str.8 = [9 x i8] c"adjtimex\00"
@.str.9 = [112 x i8] c"adjtimex() returned -1 indicating error. Unable to determine clock sync. See above perror message for details.\0A\00"
@TIME_ERROR = global i32 0
@.str.10 = [57 x i8] c"Time is not synchronized / marked as bad by the kernel.\0A\00"
@.str.11 = [80 x i8] c"Clock is less stable than allowed. Max estimated error exceeded by: %lld(usec)\0A\00"
@STA_UNSYNC = global i32 0
@.str.12 = [84 x i8] c"Clock is out of sync / in unsync state. Must be synchronized for proper operation.\0A\00"
@.str.13 = [18 x i8] c"Time is in sync!\0A\00"
define i32 @main() {
%1 = alloca %struct.timex
%2 = bitcast %struct.timex* %1 to i8*
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.1, i64 0, i64 0))
br label %55
8: ; preds = %0
%9 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str.3, i64 0, i64 0))
br label %55
14: ; preds = %8
%15 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
%17 = load i32, i32* @stderr
br i1 %16, label %20, label %18
18: ; preds = %14
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([108 x i8], [108 x i8]* @.str.5, i64 0, i64 0))
br label %55
20: ; preds = %14
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.6, i64 0, i64 0))
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([94 x i8], [94 x i8]* @.str.7, i64 0, i64 0))
%24 = call i32 @adjtimex(%struct.timex* %1)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([112 x i8], [112 x i8]* @.str.9, i64 0, i64 0))
br label %55
30: ; preds = %20
%31 = load i32, i32* @TIME_ERROR
%32 = icmp eq i32 %24, %31
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.10, i64 0, i64 0))
br label %55
36: ; preds = %30
%37 = getelementptr inbounds %struct.timex, %struct.timex* %1, i64 0, i32 0
%38 = load i64, i64* %37
%39 = icmp sgt i64 %38, 100000
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = add nsw i64 %38, -100000
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.11, i64 0, i64 0), i64 %41)
br label %55
44: ; preds = %36
%45 = getelementptr inbounds %struct.timex, %struct.timex* %1, i64 0, i32 1
%46 = load i32, i32* %45
%47 = load i32, i32* @STA_UNSYNC
%48 = and i32 %47, %46
%49 = icmp eq i32 %48, 0
%50 = load i32, i32* @stderr
br i1 %49, label %53, label %51
51: ; preds = %44
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.12, i64 0, i64 0))
br label %55
53: ; preds = %44
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.13, i64 0, i64 0))
br label %55
55: ; preds = %53, %51, %40, %33, %26, %18, %11, %5
%56 = phi i32 [ 1, %5 ], [ 0, %11 ], [ 1, %26 ], [ 1, %33 ], [ 1, %40 ], [ 1, %51 ], [ 0, %53 ], [ 1, %18 ]
ret i32 %56
}