#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 {
  int offset;
  int /*<<< orphan*/ modes;
  int /*<<< orphan*/ member_0;
};
struct timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ ADJ_OFFSET_SINGLESHOT;
int /*<<< orphan*/ EINVAL;
scalar_t__ adjtimex(struct timex *);
int /*<<< orphan*/ errno;
int adjtime(const struct timeval *in, struct timeval *out) {
  struct timex tx = {0};
  if (in) {
    if (in->tv_sec > 1000 || in->tv_usec > 1000000000) {
      errno = EINVAL;
      return -1;
    }
    tx.offset = in->tv_sec * 1000000 + in->tv_usec;
    tx.modes = ADJ_OFFSET_SINGLESHOT;
  }
  if (adjtimex(&tx) < 0)
    return -1;
  if (out) {
    out->tv_sec = tx.offset / 1000000;
    if ((out->tv_usec = tx.offset % 1000000) < 0) {
      out->tv_sec--;
      out->tv_usec += 1000000;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<adjtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1030 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     11aa <adjtime+0x8a>
mov    -0x10(%rbp),%rax
cmpl   $0x3e8,(%rax)
jg     116c <adjtime+0x4c>
mov    -0x10(%rbp),%rax
cmpl   $0x3b9aca00,0x4(%rax)
jle    118a <adjtime+0x6a>
mov    0x2e65(%rip),%rax
mov    (%rax),%ecx
mov    0x2e64(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <adjtime+0x109>
mov    -0x10(%rbp),%rax
imul   $0xf4240,(%rax),%eax
mov    -0x10(%rbp),%rcx
add    0x4(%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x28(%rbp),%rdi
call   1040 <adjtimex@plt>
cmp    $0x0,%rax
jge    11c9 <adjtime+0xa9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1229 <adjtime+0x109>
cmpq   $0x0,-0x18(%rbp)
je     1222 <adjtime+0x102>
mov    -0x28(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
mov    %edx,0x4(%rax)
cmp    $0x0,%edx
jge    121d <adjtime+0xfd>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0xf4240,%ecx
mov    %ecx,0x4(%rax)
jmp    1222 <adjtime+0x102>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adjtime>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movl   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
test   %rdi,%rdi
je     116d <adjtime+0x5d>
mov    (%rdi),%eax
cmp    $0x3e8,%eax
jg     1141 <adjtime+0x31>
mov    0x4(%rdi),%ecx
cmp    $0x3b9aca01,%ecx
jl     1155 <adjtime+0x45>
mov    0x2e90(%rip),%rax
mov    (%rax),%eax
mov    0x2e8f(%rip),%rcx
mov    %eax,(%rcx)
jmp    11b8 <adjtime+0xa8>
imul   $0xf4240,%eax,%eax
add    %eax,%ecx
mov    %ecx,(%rsp)
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rdi
call   1030 <adjtimex@plt>
test   %rax,%rax
js     11b8 <adjtime+0xa8>
xor    %eax,%eax
test   %rbx,%rbx
je     11bd <adjtime+0xad>
movslq (%rsp),%rcx
imul   $0x431bde83,%rcx,%rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x32,%rdx
add    %esi,%edx
mov    %edx,(%rbx)
imul   $0xf4240,%edx,%esi
sub    %esi,%ecx
mov    %ecx,0x4(%rbx)
jns    11bd <adjtime+0xad>
add    $0xffffffff,%edx
mov    %edx,(%rbx)
add    $0xf4240,%ecx
mov    %ecx,0x4(%rbx)
jmp    11bd <adjtime+0xad>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.timex = type { i32, i32, i32 }
@EINVAL = global i32 0
@errno = global i32 0
@ADJ_OFFSET_SINGLESHOT = global i32 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 = bitcast %struct.timex* %6 to i8*
%8 = load %struct.timeval*, %struct.timeval** %4
%9 = icmp ne %struct.timeval* %8, null
br i1 %9, label %10, label %34
10: ; preds = %2
%11 = load %struct.timeval*, %struct.timeval** %4
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = icmp sgt i32 %13, 1000
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = load %struct.timeval*, %struct.timeval** %4
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = icmp sgt i32 %18, 1000000000
br i1 %19, label %20, label %22
20: ; preds = %15, %10
%21 = load i32, i32* @EINVAL
store i32 %21, i32* @errno
store i32 -1, i32* %3
br label %64
22: ; preds = %15
%23 = load %struct.timeval*, %struct.timeval** %4
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = mul nsw i32 %25, 1000000
%27 = load %struct.timeval*, %struct.timeval** %4
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = add nsw i32 %26, %29
%31 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
store i32 %30, i32* %31
%32 = load i32, i32* @ADJ_OFFSET_SINGLESHOT
%33 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
store i32 %32, i32* %33
br label %34
34: ; preds = %22, %2
%35 = call i64 @adjtimex(%struct.timex* %6)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 -1, i32* %3
br label %64
38: ; preds = %34
%39 = load %struct.timeval*, %struct.timeval** %5
%40 = icmp ne %struct.timeval* %39, null
br i1 %40, label %41, label %63
41: ; preds = %38
%42 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
%43 = load i32, i32* %42
%44 = sdiv i32 %43, 1000000
%45 = load %struct.timeval*, %struct.timeval** %5
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %45, i32 0, i32 0
store i32 %44, i32* %46
%47 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
%48 = load i32, i32* %47
%49 = srem i32 %48, 1000000
%50 = load %struct.timeval*, %struct.timeval** %5
%51 = getelementptr inbounds %struct.timeval, %struct.timeval* %50, i32 0, i32 1
store i32 %49, i32* %51
%52 = icmp slt i32 %49, 0
br i1 %52, label %53, label %62
53: ; preds = %41
%54 = load %struct.timeval*, %struct.timeval** %5
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = add nsw i32 %56, -1
store i32 %57, i32* %55
%58 = load %struct.timeval*, %struct.timeval** %5
%59 = getelementptr inbounds %struct.timeval, %struct.timeval* %58, i32 0, i32 1
%60 = load i32, i32* %59
%61 = add nsw i32 %60, 1000000
store i32 %61, i32* %59
br label %62
62: ; preds = %53, %41
br label %63
63: ; preds = %62, %38
store i32 0, i32* %3
br label %64
64: ; preds = %63, %37, %20
%65 = load i32, i32* %3
ret i32 %65
}

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