#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ set_scheduler(int, int, unsigned long);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  unsigned long mask = -1;
  int r = 0, fd = open("/proc/sys/chronos/clear_on_sched_set", O_RDWR);
  char on = '1', buff;
  if (fd == -1) {
    perror("Cannot open proc file: are you sudo?\n");
    exit(1);
  }
  r = read(fd, &buff, 1);
  write(fd, &on, 1);
  set_scheduler(0x0000, -1, mask);
  write(fd, &buff, r);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0xffffffffffffffff,-0x18(%rbp)
ff
movl   $0x0,-0x1c(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
movb   $0x31,-0x21(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11d1 <main+0x61>
lea    0xe63(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x21(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x18(%rbp),%rdx
xor    %edi,%edi
mov    $0xffffffff,%esi
call   1060 <set_scheduler@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%edx
lea    -0x22(%rbp),%rsi
call   1030 <write@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1070 <open@plt>
movb   $0x31,0xe(%rsp)
cmp    $0xffffffff,%eax
je     11f1 <main+0x81>
mov    %eax,%ebx
lea    0xf(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %eax,%ebp
lea    0xe(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    $0xffffffff,%esi
mov    $0xffffffffffffffff,%rdx
call   1060 <set_scheduler@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe2d(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"/proc/sys/chronos/clear_on_sched_set\00"
@O_RDWR = global i32 0
@.str.1 = [38 x i8] c"Cannot open proc file: are you sudo?\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 -1, i64* %6
store i32 0, i32* %7
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %8
store i8 49, i8* %9
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i32, i32* %8
%20 = call i32 @read(i32 %19, i8* %10, i32 1)
store i32 %20, i32* %7
%21 = load i32, i32* %8
%22 = call i32 @write(i32 %21, i8* %9, i32 1)
%23 = load i64, i64* %6
%24 = call i32 @set_scheduler(i32 0, i32 -1, i64 %23)
%25 = load i32, i32* %8
%26 = load i32, i32* %7
%27 = call i32 @write(i32 %25, i8* %10, i32 %26)
%28 = load i32, i32* %8
%29 = call i32 @close(i32 %28)
ret i32 0
}

LLVM IR (-O2):
@.str = [37 x i8] c"/proc/sys/chronos/clear_on_sched_set\00"
@O_RDWR = global i32 0
@.str.1 = [38 x i8] c"Cannot open proc file: are you sudo?\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca i8
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %5)
store i8 49, i8* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @perror(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = call i32 @read(i32 %6, i8* %4, i32 1)
%13 = call i32 @write(i32 %6, i8* %3, i32 1)
%14 = tail call i32 @set_scheduler(i32 0, i32 -1, i64 -1)
%15 = call i32 @write(i32 %6, i8* %4, i32 %12)
%16 = tail call i32 @close(i32 %6)
ret i32 0
}