#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getuid();
int is_running();
int /*<<< orphan*/ stderr;
void operation_start(void) {
  if (getuid() != 0) {
    fprintf(stderr, "Root permission required.\n");
    exit(1);
  }
  int pid = is_running();
  if (pid > 0) {
    fprintf(stderr, "Zero Judge Engine is running. PID is %d.\n", pid);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<operation_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <getuid@plt>
cmp    $0x0,%rax
je     117a <operation_start+0x3a>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1040 <is_running@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    11b2 <operation_start+0x72>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<operation_start>:
push   %rax
xor    %eax,%eax
call   1030 <getuid@plt>
test   %rax,%rax
jne    115a <operation_start+0x1a>
xor    %eax,%eax
call   1040 <is_running@plt>
test   %eax,%eax
jg     117b <operation_start+0x3b>
pop    %rax
ret
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e5e(%rip),%rcx
mov    (%rcx),%edi
lea    0xe90(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Root permission required.\0A\00"
@.str.1 = [42 x i8] c"Zero Judge Engine is running. PID is %d.\0A\00"
define void @operation_start() {
%1 = alloca i32
%2 = call i64 (...) @getuid()
%3 = icmp ne i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = call i32 (...) @is_running()
store i32 %9, i32* %1
%10 = load i32, i32* %1
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = load i32, i32* %1
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %8
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Root permission required.\0A\00"
@.str.1 = [42 x i8] c"Zero Judge Engine is running. PID is %d.\0A\00"
define void @operation_start() {
%1 = tail call i64 (...) @getuid()
%2 = icmp eq i64 %1, 0
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call i32 (...) @is_running()
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %7
ret void
}