#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*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ iopl(int);
scalar_t__ mlockall(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int begin_realtime() {
  if (iopl(3) < 0) {
    perror("iopl(3)");
    fprintf(stderr, "this program must be run suid root (see chmod(1))\n");
    fprintf(stderr, "or set capabilites on the binary:\n");
    fprintf(stderr, "sudo setcap 'cap_ipc_lock+ep cap_sys_rawio+ep "
                    "cap_sys_nice+ep' <binary-name>\n");
    return -1;
  }
  if (mlockall(1) < 0) {
    perror("mlockall(1)");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<begin_realtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3,%edi
call   1030 <iopl@plt>
cmp    $0x0,%rax
jge    11b3 <begin_realtime+0x73>
lea    0xe9d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe90(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xebc(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <begin_realtime+0xa6>
mov    $0x1,%edi
call   1050 <mlockall@plt>
cmp    $0x0,%rax
jge    11df <begin_realtime+0x9f>
lea    0xede(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e6 <begin_realtime+0xa6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<begin_realtime>:
push   %rbx
mov    $0x3,%edi
call   1030 <iopl@plt>
test   %rax,%rax
js     1166 <begin_realtime+0x26>
mov    $0x1,%edi
call   1050 <mlockall@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     11a5 <begin_realtime+0x65>
pop    %rbx
ret
lea    0xe93(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e67(%rip),%rbx
mov    (%rbx),%edi
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xeab(%rip),%rsi
call   1040 <fprintf@plt>
mov    (%rbx),%edi
lea    0xec0(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11b1 <begin_realtime+0x71>
lea    0xf00(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"iopl(3)\00"
@stderr = global i32 0
@.str.1 = [51 x i8] c"this program must be run suid root (see chmod(1))\0A\00"
@.str.2 = [35 x i8] c"or set capabilites on the binary:\0A\00"
@.str.3 = [78 x i8] c"sudo setcap 'cap_ipc_lock+ep cap_sys_rawio+ep cap_sys_nice+ep' <binary-name>\0A\00"
@.str.4 = [12 x i8] c"mlockall(1)\00"
define i32 @begin_realtime() {
%1 = alloca i32
%2 = call i64 @iopl(i32 3)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %12
4: ; preds = %0
%5 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stderr
%7 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %1
br label %18
12: ; preds = %0
%13 = call i64 @mlockall(i32 1)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %18
17: ; preds = %12
store i32 0, i32* %1
br label %18
18: ; preds = %17, %15, %4
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [8 x i8] c"iopl(3)\00"
@stderr = global i32 0
@.str.1 = [51 x i8] c"this program must be run suid root (see chmod(1))\0A\00"
@.str.2 = [35 x i8] c"or set capabilites on the binary:\0A\00"
@.str.3 = [78 x i8] c"sudo setcap 'cap_ipc_lock+ep cap_sys_rawio+ep cap_sys_nice+ep' <binary-name>\0A\00"
@.str.4 = [12 x i8] c"mlockall(1)\00"
define i32 @begin_realtime() {
%1 = tail call i64 @iopl(i32 3)
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %11
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str.3, i64 0, i64 0))
br label %16
11: ; preds = %0
%12 = tail call i64 @mlockall(i32 1)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %16
16: ; preds = %11, %14, %3
%17 = phi i32 [ -1, %3 ], [ -1, %14 ], [ 0, %11 ]
ret i32 %17
}