#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 adjtimex(struct timex *);
int set_fixed_offset(long long nsec) {
  struct timex tx;
  int ret;
  int neg = 0;
  if (nsec < 0) {
    neg = 1;
    nsec = -nsec;
  }
  tx.modes = 0x0100;
  tx.time.tv_sec = nsec / 1000000000LL;
  tx.time.tv_usec = nsec % 1000000000LL;
  if (neg) {
    tx.time.tv_sec = -tx.time.tv_sec;
    if (tx.time.tv_usec) {
      tx.time.tv_usec = 1000000000LL - tx.time.tv_usec;
      tx.time.tv_sec--;
    }
  }
  tx.time.tv_usec /= 1000;
  ret = adjtimex(&tx);
  return ret;
}


x86 assembly (clang, -O0):
<set_fixed_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
jge    113f <set_fixed_offset+0x2f>
movl   $0x1,-0x28(%rbp)
xor    %eax,%eax
sub    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x100,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
cmpl   $0x0,-0x28(%rbp)
je     11a7 <set_fixed_offset+0x97>
xor    %eax,%eax
sub    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a2 <set_fixed_offset+0x92>
mov    $0x3b9aca00,%eax
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11a7 <set_fixed_offset+0x97>
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <adjtimex@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_fixed_offset>:
sub    $0x18,%rsp
mov    %rdi,%rcx
neg    %rcx
cmovs  %rdi,%rcx
mov    %rcx,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rdx
mul    %rdx
shr    $0xb,%rdx
imul   $0x3b9aca00,%rdx,%rax
sub    %rax,%rcx
movl   $0x100,(%rsp)
mov    %rdx,0x8(%rsp)
test   %rdi,%rdi
jns    1178 <set_fixed_offset+0x68>
mov    %rdx,%rax
neg    %rax
mov    %rax,0x8(%rsp)
test   %rcx,%rcx
je     1176 <set_fixed_offset+0x66>
mov    $0x3b9aca00,%eax
sub    %rcx,%rax
not    %rdx
mov    %rdx,0x8(%rsp)
mov    %rax,%rcx
jmp    1178 <set_fixed_offset+0x68>
xor    %ecx,%ecx
mov    %ecx,%eax
imul   $0x10624dd3,%rax,%rax
shr    $0x26,%rax
mov    %rax,0x10(%rsp)
mov    %rsp,%rdi
call   1030 <adjtimex@plt>
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.timex = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i64, i64 }
define i32 @set_fixed_offset(i64 %0) {
%2 = alloca %struct.timex
%3 = bitcast %struct.timex* %2 to i8*
%4 = icmp slt i64 %0, 0
%5 = sub nsw i64 0, %0
%6 = select i1 %4, i64 %5, i64 %0
%7 = getelementptr inbounds %struct.timex, %struct.timex* %2, i64 0, i32 0
store i32 256, i32* %7
%8 = udiv i64 %6, 1000000000
%9 = getelementptr inbounds %struct.timex, %struct.timex* %2, i64 0, i32 1, i32 0
store i64 %8, i64* %9
%10 = urem i64 %6, 1000000000
br i1 %4, label %11, label %17
11: ; preds = %1
%12 = sub nsw i64 0, %8
store i64 %12, i64* %9
%13 = icmp eq i64 %10, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = sub nuw nsw i64 1000000000, %10
%16 = xor i64 %8, -1
store i64 %16, i64* %9
br label %17
17: ; preds = %11, %14, %1
%18 = phi i64 [ 0, %11 ], [ %15, %14 ], [ %10, %1 ]
%19 = getelementptr inbounds %struct.timex, %struct.timex* %2, i64 0, i32 1, i32 1
%20 = trunc i64 %18 to i32
%21 = udiv i32 %20, 1000
%22 = zext i32 %21 to i64
store i64 %22, i64* %19
%23 = call i32 @adjtimex(%struct.timex* %2)
ret i32 %23
}