#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 {
  scalar_t__ offset;
  int /*<<< orphan*/ modes;
};

/* Variables and functions */
int /*<<< orphan*/ ADJ_FREQUENCY;
int /*<<< orphan*/ ADJ_OFFSET;
int adjtimex(struct timex *);
int change_skew_test(int);
int ksft_exit_fail();
int ksft_exit_pass();
int /*<<< orphan*/ printf(char *, ...);
int system(char *);
int main(int argv, char **argc) {
  struct timex tx;
  int i, ret;
  int ppm[5] = {0, 250, 500, -250, -500};
  ret = system("killall -9 ntpd");
  tx.modes = ADJ_OFFSET;
  tx.offset = 0;
  ret = adjtimex(&tx);
  if (ret < 0) {
    printf("Maybe you're not running as root?\n");
    return -1;
  }
  for (i = 0; i < 5; i++) {
    printf("Using %i ppm adjustment\n", ppm[i]);
    ret = change_skew_test(ppm[i]);
    if (ret) {
      break;
    }
  }
  tx.modes = ADJ_FREQUENCY;
  tx.offset = 0;
  adjtimex(&tx);
  if (ret) {
    printf("[FAIL]");
    return ksft_exit_fail();
  }
  printf("[OK]");
  return ksft_exit_pass();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe83(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe80(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe7e(%rip),%eax
mov    %eax,-0x30(%rbp)
lea    0xe78(%rip),%rdi
call   1050 <system@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1080 <adjtimex@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11e8 <main+0x88>
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129d <main+0x13d>
movl   $0x0,-0x24(%rbp)
cmpl   $0x5,-0x24(%rbp)
jge    1241 <main+0xe1>
movslq -0x24(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movslq -0x24(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edi
call   1070 <change_skew_test@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     122e <main+0xce>
jmp    1241 <main+0xe1>
jmp    1233 <main+0xd3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ef <main+0x8f>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1080 <adjtimex@plt>
cmpl   $0x0,-0x28(%rbp)
je     1285 <main+0x125>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1040 <ksft_exit_fail@plt>
mov    %eax,-0x4(%rbp)
jmp    129d <main+0x13d>
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <ksft_exit_pass@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe84(%rip),%rdi
call   1060 <system@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1090 <adjtimex@plt>
test   %eax,%eax
js     1287 <main+0x117>
lea    0xe63(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   1080 <change_skew_test@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    124f <main+0xdf>
lea    0xe42(%rip),%rdi
mov    $0xfa,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xfa,%edi
call   1080 <change_skew_test@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    124f <main+0xdf>
lea    0xe1f(%rip),%rdi
mov    $0x1f4,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1f4,%edi
call   1080 <change_skew_test@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    124f <main+0xdf>
lea    0xdfc(%rip),%rdi
mov    $0xffffff06,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffff06,%edi
call   1080 <change_skew_test@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    124f <main+0xdf>
lea    0xdd9(%rip),%rdi
mov    $0xfffffe0c,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xfffffe0c,%edi
call   1080 <change_skew_test@plt>
mov    %eax,%ebx
mov    0x2d82(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1090 <adjtimex@plt>
test   %ebx,%ebx
je     129a <main+0x12a>
lea    0xdb2(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1050 <ksft_exit_fail@plt>
jmp    12af <main+0x13f>
lea    0xda7(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    12af <main+0x13f>
lea    0xd8f(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1040 <ksft_exit_pass@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timex = type { i64, i32 }
@__const.main.ppm = [5 x i32] [i32 0, i32 250, i32 500, i32 -250, i32 -500]
@.str = [16 x i8] c"killall -9 ntpd\00"
@ADJ_OFFSET = global i32 0
@.str.1 = [35 x i8] c"Maybe you're not running as root?\0A\00"
@.str.2 = [25 x i8] c"Using %i ppm adjustment\0A\00"
@ADJ_FREQUENCY = global i32 0
@.str.3 = [7 x i8] c"[FAIL]\00"
@.str.4 = [5 x i8] c"[OK]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timex
%7 = alloca i32
%8 = alloca i32
%9 = alloca [5 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [5 x i32]* %9 to i8*
%11 = call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %8
%12 = load i32, i32* @ADJ_OFFSET
%13 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
store i64 0, i64* %14
%15 = call i32 @adjtimex(%struct.timex* %6)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %55
20: ; preds = %2
store i32 0, i32* %7
br label %21
21: ; preds = %39, %20
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 5
br i1 %23, label %24, label %42
24: ; preds = %21
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [5 x i32], [5 x i32]* %9, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = call i32 @change_skew_test(i32 %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %24
br label %42
38: ; preds = %24
br label %39
39: ; preds = %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %21
42: ; preds = %37, %21
%43 = load i32, i32* @ADJ_FREQUENCY
%44 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
store i32 %43, i32* %44
%45 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
store i64 0, i64* %45
%46 = call i32 @adjtimex(%struct.timex* %6)
%47 = load i32, i32* %8
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%51 = call i32 (...) @ksft_exit_fail()
store i32 %51, i32* %3
br label %55
52: ; preds = %42
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 (...) @ksft_exit_pass()
store i32 %54, i32* %3
br label %55
55: ; preds = %52, %49, %18
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%struct.timex = type { i64, i32 }
@.str = [16 x i8] c"killall -9 ntpd\00"
@ADJ_OFFSET = global i32 0
@.str.2 = [25 x i8] c"Using %i ppm adjustment\0A\00"
@ADJ_FREQUENCY = global i32 0
@.str.3 = [7 x i8] c"[FAIL]\00"
@.str.4 = [5 x i8] c"[OK]\00"
@str = [34 x i8] c"Maybe you're not running as root?\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.timex
%4 = bitcast %struct.timex* %3 to i8*
%5 = tail call i32 @system(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @ADJ_OFFSET
%7 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 1
store i32 %6, i32* %7
%8 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 0
store i64 0, i64* %8
%9 = call i32 @adjtimex(%struct.timex* %3)
%10 = icmp slt i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 0)
%13 = call i32 @change_skew_test(i32 0)
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %32
15: ; preds = %2
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %43
17: ; preds = %11
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 250)
%19 = call i32 @change_skew_test(i32 250)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %17
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 500)
%23 = call i32 @change_skew_test(i32 500)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 -250)
%27 = call i32 @change_skew_test(i32 -250)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 -500)
%31 = call i32 @change_skew_test(i32 -500)
br label %32
32: ; preds = %29, %25, %21, %17, %11
%33 = phi i32 [ %13, %11 ], [ %19, %17 ], [ %23, %21 ], [ %27, %25 ], [ %31, %29 ]
%34 = load i32, i32* @ADJ_FREQUENCY
store i32 %34, i32* %7
store i64 0, i64* %8
%35 = call i32 @adjtimex(%struct.timex* %3)
%36 = icmp eq i32 %33, 0
br i1 %36, label %40, label %37
37: ; preds = %32
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%39 = call i32 (...) @ksft_exit_fail()
br label %43
40: ; preds = %32
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%42 = call i32 (...) @ksft_exit_pass()
br label %43
43: ; preds = %40, %37, %15
%44 = phi i32 [ -1, %15 ], [ %39, %37 ], [ %42, %40 ]
ret i32 %44
}