#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  long long tv_sec;
  long long tv_usec;
};
struct timex {
  int modes;
  TYPE_1__ time;
};

/* Variables and functions */
int ADJ_NANO;
int /*<<< orphan*/ CLOCK_REALTIME;
int clock_adjtime(int /*<<< orphan*/, struct timex *);
int /*<<< orphan*/ printf(char *, ...);
int set_offset(long long offset, int use_nano) {
  struct timex tmx = {};
  int ret;
  tmx.modes = 0x0100;
  if (use_nano) {
    tmx.modes |= ADJ_NANO;
    tmx.time.tv_sec = offset / 1000000000LL;
    tmx.time.tv_usec = offset % 1000000000LL;
    if (offset < 0 && tmx.time.tv_usec) {
      tmx.time.tv_sec -= 1;
      tmx.time.tv_usec += 1000000000LL;
    }
  } else {
    tmx.time.tv_sec = offset / 1000000LL;
    tmx.time.tv_usec = offset % 1000000LL;
    if (offset < 0 && tmx.time.tv_usec) {
      tmx.time.tv_sec -= 1;
      tmx.time.tv_usec += 1000000LL;
    }
  }
  ret = clock_adjtime(CLOCK_REALTIME, &tmx);
  if (ret < 0) {
    printf("(sec: %ld  usec: %ld) ", tmx.time.tv_sec, tmx.time.tv_usec);
    printf("[FAIL]\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
movl   $0x100,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c8 <set_offset+0x98>
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
or     -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11c3 <set_offset+0x93>
cmpq   $0x0,-0x20(%rbp)
je     11c3 <set_offset+0x93>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x3b9aca00,%rax
mov    %rax,-0x20(%rbp)
jmp    1221 <set_offset+0xf1>
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    121c <set_offset+0xec>
cmpq   $0x0,-0x20(%rbp)
je     121c <set_offset+0xec>
mov    -0x28(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x20(%rbp)
jmp    1221 <set_offset+0xf1>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <clock_adjtime@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1270 <set_offset+0x140>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1277 <set_offset+0x147>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_offset>:
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0x100,(%rsp)
test   %esi,%esi
je     11b0 <set_offset+0x80>
mov    0x2e8a(%rip),%rax
mov    $0x100,%ecx
or     (%rax),%ecx
mov    %ecx,(%rsp)
movabs $0x112e0be826d694b3,%rcx
0b 2e 11
mov    %rdi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1a,%rdx
add    %rax,%rdx
mov    %rdx,0x8(%rsp)
imul   $0x3b9aca00,%rdx,%rcx
mov    %rdi,%rax
sub    %rcx,%rax
mov    %rax,0x10(%rsp)
test   %rdi,%rdi
jns    1203 <set_offset+0xd3>
test   %rax,%rax
je     1203 <set_offset+0xd3>
add    $0xffffffffffffffff,%rdx
mov    %rdx,0x8(%rsp)
add    $0x3b9aca00,%rax
jmp    11fe <set_offset+0xce>
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %rdi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
mov    %rdx,0x8(%rsp)
imul   $0xf4240,%rdx,%rcx
mov    %rdi,%rax
sub    %rcx,%rax
mov    %rax,0x10(%rsp)
test   %rdi,%rdi
jns    1203 <set_offset+0xd3>
test   %rax,%rax
je     1203 <set_offset+0xd3>
add    $0xffffffffffffffff,%rdx
mov    %rdx,0x8(%rsp)
add    $0xf4240,%rax
mov    %rax,0x10(%rsp)
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_adjtime@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
js     1221 <set_offset+0xf1>
add    $0x18,%rsp
ret
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
lea    0xdce(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdd7(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timex = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@ADJ_NANO = global i32 0
@CLOCK_REALTIME = global i32 0
@.str = [23 x i8] c"(sec: %ld usec: %ld) \00"
@.str.1 = [8 x i8] c"[FAIL]\0A\00"
define i32 @set_offset(i64 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.timex
%7 = alloca i32
store i64 %0, i64* %4
store i32 %1, i32* %5
%8 = bitcast %struct.timex* %6 to i8*
%9 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
store i32 256, i32* %9
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %42
12: ; preds = %2
%13 = load i32, i32* @ADJ_NANO
%14 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 0
%15 = load i32, i32* %14
%16 = or i32 %15, %13
store i32 %16, i32* %14
%17 = load i64, i64* %4
%18 = sdiv i64 %17, 1000000000
%19 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%20 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %19, i32 0, i32 0
store i64 %18, i64* %20
%21 = load i64, i64* %4
%22 = srem i64 %21, 1000000000
%23 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 1
store i64 %22, i64* %24
%25 = load i64, i64* %4
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %41
27: ; preds = %12
%28 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %28, i32 0, i32 1
%30 = load i64, i64* %29
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%34 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %33, i32 0, i32 0
%35 = load i64, i64* %34
%36 = sub nsw i64 %35, 1
store i64 %36, i64* %34
%37 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 1
%39 = load i64, i64* %38
%40 = add nsw i64 %39, 1000000000
store i64 %40, i64* %38
br label %41
41: ; preds = %32, %27, %12
br label %68
42: ; preds = %2
%43 = load i64, i64* %4
%44 = sdiv i64 %43, 1000000
%45 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%46 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %45, i32 0, i32 0
store i64 %44, i64* %46
%47 = load i64, i64* %4
%48 = srem i64 %47, 1000000
%49 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%50 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %49, i32 0, i32 1
store i64 %48, i64* %50
%51 = load i64, i64* %4
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %67
53: ; preds = %42
%54 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 1
%56 = load i64, i64* %55
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %67
58: ; preds = %53
%59 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%60 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %59, i32 0, i32 0
%61 = load i64, i64* %60
%62 = sub nsw i64 %61, 1
store i64 %62, i64* %60
%63 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%64 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %63, i32 0, i32 1
%65 = load i64, i64* %64
%66 = add nsw i64 %65, 1000000
store i64 %66, i64* %64
br label %67
67: ; preds = %58, %53, %42
br label %68
68: ; preds = %67, %41
%69 = load i32, i32* @CLOCK_REALTIME
%70 = call i32 @clock_adjtime(i32 %69, %struct.timex* %6)
store i32 %70, i32* %7
%71 = load i32, i32* %7
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %82
73: ; preds = %68
%74 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%75 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %74, i32 0, i32 0
%76 = load i64, i64* %75
%77 = getelementptr inbounds %struct.timex, %struct.timex* %6, i32 0, i32 1
%78 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %77, i32 0, i32 1
%79 = load i64, i64* %78
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %76, i64 %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %83
82: ; preds = %68
store i32 0, i32* %3
br label %83
83: ; preds = %82, %73
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
%struct.timex = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
@ADJ_NANO = global i32 0
@CLOCK_REALTIME = global i32 0
@.str = [23 x i8] c"(sec: %ld usec: %ld) \00"
@str = [7 x i8] c"[FAIL]\00"
define i32 @set_offset(i64 %0, i32 %1) {
%3 = alloca %struct.timex
%4 = bitcast %struct.timex* %3 to i8*
%5 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 0
store i32 256, i32* %5
%6 = icmp eq i32 %1, 0
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = load i32, i32* @ADJ_NANO
%9 = or i32 %8, 256
store i32 %9, i32* %5
%10 = sdiv i64 %0, 1000000000
%11 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 1, i32 0
store i64 %10, i64* %11
%12 = srem i64 %0, 1000000000
%13 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 1, i32 1
store i64 %12, i64* %13
%14 = icmp slt i64 %0, 0
%15 = icmp ne i64 %12, 0
%16 = and i1 %14, %15
br i1 %16, label %17, label %31
17: ; preds = %7
%18 = add nsw i64 %10, -1
store i64 %18, i64* %11
%19 = add nsw i64 %12, 1000000000
store i64 %19, i64* %13
br label %31
20: ; preds = %2
%21 = sdiv i64 %0, 1000000
%22 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 1, i32 0
store i64 %21, i64* %22
%23 = srem i64 %0, 1000000
%24 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 1, i32 1
store i64 %23, i64* %24
%25 = icmp slt i64 %0, 0
%26 = icmp ne i64 %23, 0
%27 = and i1 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = add nsw i64 %21, -1
store i64 %29, i64* %22
%30 = add nsw i64 %23, 1000000
store i64 %30, i64* %24
br label %31
31: ; preds = %20, %28, %7, %17
%32 = load i32, i32* @CLOCK_REALTIME
%33 = call i32 @clock_adjtime(i32 %32, %struct.timex* %3)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %31
%36 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 1, i32 0
%37 = load i64, i64* %36
%38 = getelementptr inbounds %struct.timex, %struct.timex* %3, i64 0, i32 1, i32 1
%39 = load i64, i64* %38
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i64 %37, i64 %39)
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %42
42: ; preds = %31, %35
%43 = phi i32 [ -1, %35 ], [ 0, %31 ]
ret i32 %43
}