#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 tv_sec;
  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_bad_offset(long sec, long usec, int use_nano) {
  struct timex tmx = {};
  int ret;
  tmx.modes = 0x0100;
  if (use_nano) {
    tmx.modes |= ADJ_NANO;
  }
  tmx.time.tv_sec = sec;
  tmx.time.tv_usec = usec;
  ret = clock_adjtime(CLOCK_REALTIME, &tmx);
  if (ret >= 0) {
    printf("Invalid (sec: %ld  usec: %ld) did not fail! ", tmx.time.tv_sec,
           tmx.time.tv_usec);
    printf("[FAIL]\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_bad_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1050 <memset@plt>
movl   $0x100,-0x38(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1173 <set_bad_offset+0x43>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
or     -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
call   1030 <clock_adjtime@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jl     11d2 <set_bad_offset+0xa2>
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <set_bad_offset+0xa9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_bad_offset>:
sub    $0x18,%rsp
movq   $0x0,(%rsp)
movl   $0x100,(%rsp)
test   %edx,%edx
je     1158 <set_bad_offset+0x28>
mov    0x2e92(%rip),%rax
mov    $0x100,%ecx
or     (%rax),%ecx
mov    %ecx,(%rsp)
mov    %rdi,0x8(%rsp)
mov    %rsi,0x10(%rsp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_adjtime@plt>
test   %eax,%eax
js     11a5 <set_bad_offset+0x75>
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe97(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
ret
xor    %eax,%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 = [45 x i8] c"Invalid (sec: %ld usec: %ld) did not fail! \00"
@.str.1 = [8 x i8] c"[FAIL]\0A\00"
define i32 @set_bad_offset(i64 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca %struct.timex
%9 = alloca i32
store i64 %0, i64* %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%10 = bitcast %struct.timex* %8 to i8*
%11 = getelementptr inbounds %struct.timex, %struct.timex* %8, i32 0, i32 0
store i32 256, i32* %11
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %3
%15 = load i32, i32* @ADJ_NANO
%16 = getelementptr inbounds %struct.timex, %struct.timex* %8, i32 0, i32 0
%17 = load i32, i32* %16
%18 = or i32 %17, %15
store i32 %18, i32* %16
br label %19
19: ; preds = %14, %3
%20 = load i64, i64* %5
%21 = getelementptr inbounds %struct.timex, %struct.timex* %8, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i64 %20, i64* %22
%23 = load i64, i64* %6
%24 = getelementptr inbounds %struct.timex, %struct.timex* %8, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 1
store i64 %23, i64* %25
%26 = load i32, i32* @CLOCK_REALTIME
%27 = call i32 @clock_adjtime(i32 %26, %struct.timex* %8)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp sge i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %19
%31 = getelementptr inbounds %struct.timex, %struct.timex* %8, i32 0, i32 1
%32 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %31, i32 0, i32 0
%33 = load i64, i64* %32
%34 = getelementptr inbounds %struct.timex, %struct.timex* %8, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 1
%36 = load i64, i64* %35
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i64 %33, i64 %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %40
39: ; preds = %19
store i32 0, i32* %4
br label %40
40: ; preds = %39, %30
%41 = load i32, i32* %4
ret i32 %41
}

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 = [45 x i8] c"Invalid (sec: %ld usec: %ld) did not fail! \00"
@str = [7 x i8] c"[FAIL]\00"
define i32 @set_bad_offset(i64 %0, i64 %1, i32 %2) {
%4 = alloca %struct.timex
%5 = bitcast %struct.timex* %4 to i8*
%6 = bitcast %struct.timex* %4 to i64*
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.timex, %struct.timex* %4, i64 0, i32 0
store i32 256, i32* %7
%8 = icmp eq i32 %2, 0
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = load i32, i32* @ADJ_NANO
%11 = or i32 %10, 256
store i32 %11, i32* %7
br label %12
12: ; preds = %9, %3
%13 = getelementptr inbounds %struct.timex, %struct.timex* %4, i64 0, i32 1, i32 0
store i64 %0, i64* %13
%14 = getelementptr inbounds %struct.timex, %struct.timex* %4, i64 0, i32 1, i32 1
store i64 %1, i64* %14
%15 = load i32, i32* @CLOCK_REALTIME
%16 = call i32 @clock_adjtime(i32 %15, %struct.timex* %4)
%17 = icmp sgt i32 %16, -1
br i1 %17, label %18, label %23
18: ; preds = %12
%19 = load i64, i64* %13
%20 = load i64, i64* %14
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i64 %19, i64 %20)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %23
23: ; preds = %12, %18
%24 = phi i32 [ -1, %18 ], [ 0, %12 ]
ret i32 %24
}