#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*/ SIGTERM;
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ getuid();
int is_running();
int kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ setvbuf(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/,
                   int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int strlen(char *);
void operation_stop(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 not running.\n");
    exit(1);
  }
  if (setvbuf(stdout, NULL, _IONBF, 0) != 0) {
    fprintf(stderr, "Fail to make standard output stream unbuffered.\n");
    exit(1);
  }
  printf("Zero Judge Engine is running. PID is %d.\n", pid);
  if (kill(pid, SIGTERM) == -1) {
    fprintf(stderr, "Fail to terminate Zero Judge Engine. Retry later.\n");
    exit(1);
  }
  printf("Wait for Zero Judge Engine terminating...  ");
  char busy_char[] = "/-\\|";
  for (int i = 0; is_running(); ++i) {
    printf("\b%c", busy_char[i % strlen(busy_char)]);
    sleep(1);
  }
  printf("\nDone.\n");
  exit(0);
}


x86 assembly (clang, -O0):
<operation_stop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <getuid@plt>
cmp    $0x0,%rax
je     11c8 <operation_stop+0x38>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x0,%al
call   1060 <is_running@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    11fb <operation_stop+0x6b>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
mov    0x2dd5(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
xor    %ecx,%ecx
call   1090 <setvbuf@plt>
cmp    $0x0,%rax
je     1241 <operation_stop+0xb1>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x4(%rbp),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2d8c(%rip),%rax
mov    (%rax),%esi
call   1080 <kill@plt>
cmp    $0xffffffff,%eax
jne    128b <operation_stop+0xfb>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0xe59(%rip),%eax
mov    %eax,-0x9(%rbp)
mov    0xe54(%rip),%al
mov    %al,-0x5(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1060 <is_running@plt>
cmp    $0x0,%eax
je     1307 <operation_stop+0x177>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x9(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cltd
idiv   %ecx
movslq %edx,%rax
movsbl -0x9(%rbp,%rax,1),%esi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <sleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12b2 <operation_stop+0x122>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<operation_stop>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <getuid@plt>
test   %rax,%rax
jne    11d1 <operation_stop+0x31>
xor    %eax,%eax
call   1070 <is_running@plt>
test   %eax,%eax
jne    11f0 <operation_stop+0x50>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
jmp    11e1 <operation_stop+0x41>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %eax,%ebx
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    0x2dde(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   10a0 <setvbuf@plt>
test   %rax,%rax
jne    1249 <operation_stop+0xa9>
lea    0xe56(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1090 <kill@plt>
cmp    $0xffffffff,%eax
jne    125b <operation_stop+0xbb>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
jmp    11e1 <operation_stop+0x41>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
jmp    11e1 <operation_stop+0x41>
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movb   $0x0,0xc(%rsp)
movl   $0x7c5c2d2f,0x8(%rsp)
7c
xor    %eax,%eax
call   1070 <is_running@plt>
test   %eax,%eax
je     12c6 <operation_stop+0x126>
lea    0x8(%rsp),%r14
lea    0xe70(%rip),%rbx
xor    %ebp,%ebp
nop
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
movsbl 0x8(%rsp,%rdx,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10c0 <sleep@plt>
add    $0x1,%ebp
xor    %eax,%eax
call   1070 <is_running@plt>
test   %eax,%eax
jne    1290 <operation_stop+0xf0>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Root permission required.\0A\00"
@.str.1 = [35 x i8] c"Zero Judge Engine is not running.\0A\00"
@stdout = global i32 0
@_IONBF = global i32 0
@.str.2 = [49 x i8] c"Fail to make standard output stream unbuffered.\0A\00"
@.str.3 = [42 x i8] c"Zero Judge Engine is running. PID is %d.\0A\00"
@SIGTERM = global i32 0
@.str.4 = [51 x i8] c"Fail to terminate Zero Judge Engine. Retry later.\0A\00"
@.str.5 = [44 x i8] c"Wait for Zero Judge Engine terminating... \00"
@__const.operation_stop.busy_char = [5 x i8] c"/-\\|\00"
@.str.6 = [4 x i8] c"\08%c\00"
@.str.7 = [8 x i8] c"\0ADone.\0A\00"
define void @operation_stop() {
%1 = alloca i32
%2 = alloca [5 x i8]
%3 = alloca i32
%4 = call i64 (...) @getuid()
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = call i32 (...) @is_running()
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = load i32, i32* @stdout
%20 = load i32, i32* @_IONBF
%21 = call i64 @setvbuf(i32 %19, i32* null, i32 %20, i32 0)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = load i32, i32* %1
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %1
%31 = load i32, i32* @SIGTERM
%32 = call i32 @kill(i32 %30, i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %27
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
%40 = bitcast [5 x i8]* %2 to i8*
store i32 0, i32* %3
br label %41
41: ; preds = %55, %38
%42 = call i32 (...) @is_running()
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %58
44: ; preds = %41
%45 = load i32, i32* %3
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = srem i32 %45, %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %52)
%54 = call i32 @sleep(i32 1)
br label %55
55: ; preds = %44
%56 = load i32, i32* %3
%57 = add nsw i32 %56, 1
store i32 %57, i32* %3
br label %41
58: ; preds = %41
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%60 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Root permission required.\0A\00"
@.str.1 = [35 x i8] c"Zero Judge Engine is not running.\0A\00"
@stdout = global i32 0
@_IONBF = global i32 0
@.str.2 = [49 x i8] c"Fail to make standard output stream unbuffered.\0A\00"
@.str.3 = [42 x i8] c"Zero Judge Engine is running. PID is %d.\0A\00"
@SIGTERM = global i32 0
@.str.4 = [51 x i8] c"Fail to terminate Zero Judge Engine. Retry later.\0A\00"
@.str.5 = [44 x i8] c"Wait for Zero Judge Engine terminating... \00"
@__const.operation_stop.busy_char = [5 x i8] c"/-\\|\00"
@.str.6 = [4 x i8] c"\08%c\00"
@str = [7 x i8] c"\0ADone.\00"
define void @operation_stop() {
%1 = alloca [5 x i8]
%2 = tail call i64 (...) @getuid()
%3 = icmp eq i64 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call i32 (...) @is_running()
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = load i32, i32* @stdout
%17 = load i32, i32* @_IONBF
%18 = tail call i64 @setvbuf(i32 %16, i32* null, i32 %17, i32 0)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%26 = load i32, i32* @SIGTERM
%27 = tail call i32 @kill(i32 %9, i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %33
29: ; preds = %24
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0))
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.5, i64 0, i64 0))
%35 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%36 = call i32 (...) @is_running()
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %41, %33
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %33, %41
%42 = phi i32 [ %51, %41 ], [ 0, %33 ]
%43 = call i32 @strlen(i8* %35)
%44 = srem i32 %42, %43
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%50 = call i32 @sleep(i32 1)
%51 = add nuw nsw i32 %42, 1
%52 = call i32 (...) @is_running()
%53 = icmp eq i32 %52, 0
br i1 %53, label %38, label %41
}