#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 unset_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):
<unset_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 <unset_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    121a <unset_flags+0xda>
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
xor    $0xffffffff,%eax
and    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <adjtimex@plt>
cmp    $0xffffffff,%eax
jne    1213 <unset_flags+0xd3>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe17(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    121a <unset_flags+0xda>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unset_flags>:
push   %rbp
push   %rbx
push   %rax
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1040 <adjtimex@plt>
cmp    $0xffffffff,%eax
je     1186 <unset_flags+0x56>
mov    0x2e91(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e7c(%rip),%rax
mov    0x2e8d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
not    %ecx
and    %ecx,(%rsp)
mov    %rsp,%rdi
call   1040 <adjtimex@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    11b6 <unset_flags+0x86>
lea    0xe95(%rip),%rbx
jmp    118d <unset_flags+0x5d>
lea    0xe73(%rip),%rbx
mov    0x2e34(%rip),%rax
mov    (%rax),%ebp
mov    0x2e23(%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 @unset_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 %29
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 = xor i32 %16, -1
%18 = getelementptr inbounds %struct.timex, %struct.timex* %2, i32 0, i32 0
%19 = load i32, i32* %18
%20 = and i32 %19, %17
store i32 %20, i32* %18
%21 = call i32 @adjtimex(%struct.timex* %2)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %11
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %26)
store i32 -1, i32* %1
br label %29
28: ; preds = %11
store i32 0, i32* %1
br label %29
29: ; preds = %28, %23, %6
%30 = load i32, i32* %1
ret i32 %30
}

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 @unset_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 %18, 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 = xor i32 %11, -1
%13 = bitcast i64* %1 to i32*
%14 = load i32, i32* %13
%15 = and i32 %14, %12
store i32 %15, i32* %13
%16 = call i32 @adjtimex(%struct.timex* %2)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %6, %0
%19 = 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 ]
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @fprintf(i32 %20, i8* %19, i8* %22)
br label %24
24: ; preds = %18, %6
%25 = phi i32 [ 0, %6 ], [ -1, %18 ]
ret i32 %25
}