#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 offset;
  scalar_t__ modes;
};
struct timeval {
  long tv_usec;
  long tv_sec;
};

/* Variables and functions */
scalar_t__ ADJ_OFFSET_SINGLESHOT;
int adjtimex(struct timex *);
int adjtime(const struct timeval *itv, struct timeval *otv) {
  struct timex tmp;
  if (itv) {
    tmp.offset = (itv->tv_usec % 1000000L) +
                 (itv->tv_sec + itv->tv_usec / 1000000L) * 1000000L;
    tmp.modes = ADJ_OFFSET_SINGLESHOT;
  } else
    tmp.modes = 0;
  if (adjtimex(&tmp) == -1)
    return -1;
  if (otv) {
    otv->tv_usec = tmp.offset % 1000000;
    otv->tv_sec = tmp.offset / 1000000;
  }
  return 0;
}


x86 assembly (clang, -O0):
<adjtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118c <adjtime+0x7c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
imul   $0xf4240,%rax,%rax
add    %rax,%rdx
mov    %rdx,-0x28(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1194 <adjtime+0x84>
movq   $0x0,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
call   1030 <adjtimex@plt>
cmp    $0xffffffff,%eax
jne    11b2 <adjtime+0xa2>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <adjtime+0xe2>
cmpq   $0x0,-0x18(%rbp)
je     11eb <adjtime+0xdb>
mov    -0x28(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    -0x18(%rbp),%rax
mov    %rdx,(%rax)
mov    -0x28(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adjtime>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
movabs $0x431bde82d7b634db,%r14
de 1b 43
test   %rdi,%rdi
je     1169 <adjtime+0x59>
mov    (%rdi),%rcx
mov    %rcx,%rax
imul   %r14
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
imul   $0xf4240,%rdx,%rax
sub    %rax,%rcx
add    0x8(%rdi),%rdx
imul   $0xf4240,%rdx,%rax
add    %rcx,%rax
mov    %rax,0x8(%rsp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%rax
jmp    116b <adjtime+0x5b>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <adjtimex@plt>
cmp    $0xffffffff,%eax
je     11b2 <adjtime+0xa2>
xor    %ecx,%ecx
test   %rbx,%rbx
je     11b7 <adjtime+0xa7>
mov    0x8(%rsp),%rsi
mov    %rsi,%rax
imul   %r14
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
imul   $0xf4240,%rdx,%rax
sub    %rax,%rsi
mov    %rsi,(%rbx)
mov    %rdx,0x8(%rbx)
jmp    11b7 <adjtime+0xa7>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
%struct.timex = type { i64, i64 }
@ADJ_OFFSET_SINGLESHOT = global i64 0
define i32 @adjtime(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca i32
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca %struct.timex
store %struct.timeval* %0, %struct.timeval** %4
store %struct.timeval* %1, %struct.timeval** %5
%7 = load %struct.timeval*, %struct.timeval** %4
%8 = icmp ne %struct.timeval* %7, null
br i1 %8, label %9, label %27
9: ; preds = %2
%10 = load %struct.timeval*, %struct.timeval** %4
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = srem i64 %12, 1000000
%14 = load %struct.timeval*, %struct.timeval** %4
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%16 = load i64, i64* %15
%17 = load %struct.timeval*, %struct.timeval** %4
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = sdiv i64 %19, 1000000
%21 = add nsw i64 %16, %20
%22 = mul nsw i64 %21, 1000000
%23 = add nsw i64 %13, %22
%24 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
store i64 %23, i64* %24
%25 = load i64, i64* @ADJ_OFFSET_SINGLESHOT
%26 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
store i64 %25, i64* %26
br label %29
27: ; preds = %2
%28 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
store i64 0, i64* %28
br label %29
29: ; preds = %27, %9
%30 = call i32 @adjtimex(%struct.timex* %6)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 -1, i32* %3
br label %48
33: ; preds = %29
%34 = load %struct.timeval*, %struct.timeval** %5
%35 = icmp ne %struct.timeval* %34, null
br i1 %35, label %36, label %47
36: ; preds = %33
%37 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
%38 = load i64, i64* %37
%39 = srem i64 %38, 1000000
%40 = load %struct.timeval*, %struct.timeval** %5
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %40, i32 0, i32 0
store i64 %39, i64* %41
%42 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
%43 = load i64, i64* %42
%44 = sdiv i64 %43, 1000000
%45 = load %struct.timeval*, %struct.timeval** %5
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %45, i32 0, i32 1
store i64 %44, i64* %46
br label %47
47: ; preds = %36, %33
store i32 0, i32* %3
br label %48
48: ; preds = %47, %32
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
%struct.timex = type { i64, i64 }
@ADJ_OFFSET_SINGLESHOT = global i64 0
define i32 @adjtime(%struct.timeval* %0, %struct.timeval* writeonly %1) {
%3 = alloca %struct.timex
%4 = bitcast %struct.timex* %3 to i8*
%5 = icmp eq %struct.timeval* %0, null
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%8 = load i64, i64* %7
%9 = srem i64 %8, 1000000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%11 = load i64, i64* %10
%12 = sdiv i64 %8, 1000000
%13 = add nsw i64 %11, %12
%14 = mul nsw i64 %13, 1000000
%15 = add nsw i64 %14, %9
%16 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 0
store i64 %15, i64* %16
%17 = load i64, i64* @ADJ_OFFSET_SINGLESHOT
br label %18
18: ; preds = %2, %6
%19 = phi i64 [ %17, %6 ], [ 0, %2 ]
%20 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 1
store i64 %19, i64* %20
%21 = call i32 @adjtimex(%struct.timex* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %32, label %23
23: ; preds = %18
%24 = icmp eq %struct.timeval* %1, null
br i1 %24, label %32, label %25
25: ; preds = %23
%26 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 0
%27 = load i64, i64* %26
%28 = srem i64 %27, 1000000
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i64 %28, i64* %29
%30 = sdiv i64 %27, 1000000
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i64 %30, i64* %31
br label %32
32: ; preds = %23, %25, %18
%33 = phi i32 [ -1, %18 ], [ 0, %25 ], [ 0, %23 ]
ret i32 %33
}