#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 status;
  int /*<<< orphan*/ modes;
};

/* Variables and functions */
int /*<<< orphan*/ ADJ_STATUS;
int STA_PPSFREQ;
int STA_PPSTIME;
int adjtimex(struct timex *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int set_flags() {
  struct timex tmx = {.modes = 0};
  if (adjtimex(&tmx) == -1) {
    fprintf(stderr, "adjtimex get failed: %s\n", strerror(errno));
    return -1;
  }
  tmx.modes = ADJ_STATUS;
  tmx.status |= (STA_PPSFREQ | STA_PPSTIME);
  if (adjtimex(&tmx) == -1) {
    fprintf(stderr, "adjtimex set failed: %s\n", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<set_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
lea    -0x10(%rbp),%rdi
call   1050 <adjtimex@plt>
cmp    $0xffffffff,%eax
jne    11a2 <set_flags+0x62>
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe6f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1217 <set_flags+0xd7>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    0x2e32(%rip),%rcx
or     (%rcx),%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <adjtimex@plt>
cmp    $0xffffffff,%eax
jne    1210 <set_flags+0xd0>
mov    0x2de9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe1a(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1217 <set_flags+0xd7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_flags>:
push   %rbp
push   %rbx
push   %rax
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1040 <adjtimex@plt>
cmp    $0xffffffff,%eax
je     1184 <set_flags+0x54>
mov    0x2e89(%rip),%rax
mov    0x2e9a(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
or     %ecx,(%rsp)
mov    %rsp,%rdi
call   1040 <adjtimex@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    11b4 <set_flags+0x84>
lea    0xe97(%rip),%rbx
jmp    118b <set_flags+0x5b>
lea    0xe75(%rip),%rbx
mov    0x2e36(%rip),%rax
mov    (%rax),%ebp
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timex = type { i32, i32 }
@stderr = global i32 0
@.str = [25 x i8] c"adjtimex get failed: %s\0A\00"
@errno = global i32 0
@ADJ_STATUS = global i32 0
@STA_PPSFREQ = global i32 0
@STA_PPSTIME = global i32 0
@.str.1 = [25 x i8] c"adjtimex set failed: %s\0A\00"
define i32 @set_flags() {
%1 = alloca i32
%2 = alloca %struct.timex
%3 = bitcast %struct.timex* %2 to i8*
%4 = call i32 @adjtimex(%struct.timex* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %9)
store i32 -1, i32* %1
br label %28
11: ; preds = %0
%12 = load i32, i32* @ADJ_STATUS
%13 = getelementptr inbounds %struct.timex, %struct.timex* %2, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @STA_PPSFREQ
%15 = load i32, i32* @STA_PPSTIME
%16 = or i32 %14, %15
%17 = getelementptr inbounds %struct.timex, %struct.timex* %2, i32 0, i32 0
%18 = load i32, i32* %17
%19 = or i32 %18, %16
store i32 %19, i32* %17
%20 = call i32 @adjtimex(%struct.timex* %2)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %27
22: ; preds = %11
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 -1, i32* %1
br label %28
27: ; preds = %11
store i32 0, i32* %1
br label %28
28: ; preds = %27, %22, %6
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
%struct.timex = type { i32, i32 }
@stderr = global i32 0
@.str = [25 x i8] c"adjtimex get failed: %s\0A\00"
@errno = global i32 0
@ADJ_STATUS = global i32 0
@STA_PPSFREQ = global i32 0
@STA_PPSTIME = global i32 0
@.str.1 = [25 x i8] c"adjtimex set failed: %s\0A\00"
define i32 @set_flags() {
%1 = alloca i64
%2 = bitcast i64* %1 to %struct.timex*
%3 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%4 = call i32 @adjtimex(%struct.timex* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %17, label %6
6: ; preds = %0
%7 = load i32, i32* @ADJ_STATUS
%8 = getelementptr inbounds %struct.timex, %struct.timex* %2, i64 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* @STA_PPSFREQ
%10 = load i32, i32* @STA_PPSTIME
%11 = or i32 %10, %9
%12 = bitcast i64* %1 to i32*
%13 = load i32, i32* %12
%14 = or i32 %11, %13
store i32 %14, i32* %12
%15 = call i32 @adjtimex(%struct.timex* %2)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %6, %0
%18 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), %6 ]
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 @fprintf(i32 %19, i8* %18, i8* %21)
br label %23
23: ; preds = %17, %6
%24 = phi i32 [ 0, %6 ], [ -1, %17 ]
ret i32 %24
}