#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 load();
char *nogames();
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ workhours();
void gr(int s) {
  char *txt = 0, buf[1024];
  int ld = 0;
  static char *warnings[3] = {
      "If things don't look better within 3 minutes, the game will pause.\r\n",
      "The game will close temporarily 2 minutes from now.\r\n",
      "WARNING: The game will close in 1 minute.\r\n"};
  static int wnr = 0;
  extern int slow_death, shutdown;
  void send_to_all(char *messg);
  void coma(int s);
  if (((ld = load()) >= 6) || (txt = nogames()) || slow_death) {
    if (ld >= 6) {
      sprintf(buf, "The system load is greater than 6.0 (%d)\r\n", ld);
      send_to_all(buf);
    } else if (slow_death)
      send_to_all("The game is dying.\r\n");
    else {
      strcpy(buf, "Game playing is no longer permitted on this machine:\r\n");
      strcat(buf, txt);
      strcat(buf, "\r\n");
      send_to_all(buf);
    }
    if (wnr < 3)
      send_to_all(warnings[wnr++]);
    else if (ld >= 6) {
      coma(s);
      wnr = 0;
    } else
      shutdown = 1;
  } else if (workhours())
    shutdown = 1;
  else if (wnr) {
    send_to_all("Things look brighter now - you can continue playing.\r\n");
    wnr = 0;
  }
}


x86 assembly (clang, -O0):
<gr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x414(%rbp)
mov    $0x0,%al
call   1090 <load@plt>
mov    %eax,-0x414(%rbp)
cmp    $0x6,%eax
jge    11db <gr+0x5b>
mov    $0x0,%al
call   1050 <nogames@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11db <gr+0x5b>
mov    0x2e16(%rip),%rax
cmpl   $0x0,(%rax)
je     12eb <gr+0x16b>
cmpl   $0x6,-0x414(%rbp)
jl     1212 <gr+0x92>
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%edx
lea    0xeab(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x410(%rbp),%rdi
call   1040 <send_to_all@plt>
jmp    127a <gr+0xfa>
mov    0x2dcf(%rip),%rax
cmpl   $0x0,(%rax)
je     1233 <gr+0xb3>
lea    0xea9(%rip),%rdi
call   1040 <send_to_all@plt>
jmp    1275 <gr+0xf5>
lea    -0x410(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x410(%rbp),%rdi
call   1040 <send_to_all@plt>
jmp    127a <gr+0xfa>
cmpl   $0x3,0x2e0b(%rip)
jge    12b0 <gr+0x130>
mov    0x2dff(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2df4(%rip)
movslq %eax,%rcx
lea    0x2dce(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1040 <send_to_all@plt>
jmp    12e6 <gr+0x166>
cmpl   $0x6,-0x414(%rbp)
jl     12d4 <gr+0x154>
mov    -0x4(%rbp),%edi
call   1060 <coma@plt>
movl   $0x0,0x2dbd(%rip)
jmp    12e1 <gr+0x161>
mov    0x2cfd(%rip),%rax
movl   $0x1,(%rax)
jmp    12e6 <gr+0x166>
jmp    133b <gr+0x1bb>
mov    $0x0,%al
call   1070 <workhours@plt>
cmp    $0x0,%rax
je     130e <gr+0x18e>
mov    0x2cd5(%rip),%rax
movl   $0x1,(%rax)
jmp    1336 <gr+0x1b6>
cmpl   $0x0,0x2d77(%rip)
je     1331 <gr+0x1b1>
lea    0xdfc(%rip),%rdi
call   1040 <send_to_all@plt>
movl   $0x0,0x2d5b(%rip)
jmp    1336 <gr+0x1b6>
jmp    133b <gr+0x1bb>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gr>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ebp
xor    %eax,%eax
call   1090 <load@plt>
cmp    $0x5,%eax
jle    11cd <gr+0x4d>
lea    0xf13(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <send_to_all@plt>
mov    0x2ea9(%rip),%eax
cmp    $0x2,%eax
jle    126a <gr+0xea>
mov    %ebp,%edi
call   1060 <coma@plt>
jmp    1212 <gr+0x92>
xor    %eax,%eax
call   1050 <nogames@plt>
mov    %rax,%rbx
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
test   %rbx,%rbx
jne    121e <gr+0x9e>
test   %eax,%eax
jne    121e <gr+0x9e>
xor    %eax,%eax
call   1070 <workhours@plt>
test   %rax,%rax
jne    128a <gr+0x10a>
cmpl   $0x0,0x2e64(%rip)
je     1297 <gr+0x117>
lea    0xf1d(%rip),%rdi
call   1040 <send_to_all@plt>
movl   $0x0,0x2e48(%rip)
jmp    1297 <gr+0x117>
test   %eax,%eax
je     122b <gr+0xab>
lea    0xeb5(%rip),%rdi
jmp    125a <gr+0xda>
lea    0xec1(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <strcat@plt>
lea    0xe8c(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
call   1040 <send_to_all@plt>
mov    0x2dff(%rip),%eax
cmp    $0x3,%eax
jge    128a <gr+0x10a>
lea    0x1(%rax),%ecx
mov    %ecx,0x2df1(%rip)
cltq
lea    0xd84(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
call   1040 <send_to_all@plt>
jmp    1297 <gr+0x117>
mov    0x2d47(%rip),%rax
movl   $0x1,(%rax)
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@gr.warnings = internal global [3 x i8*] [i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i32 0, i32 0)]
@.str = [69 x i8] c"If things don't look better within 3 minutes, the game will pause.\0D\0A\00"
@.str.1 = [54 x i8] c"The game will close temporarily 2 minutes from now.\0D\0A\00"
@.str.2 = [44 x i8] c"WARNING: The game will close in 1 minute.\0D\0A\00"
@gr.wnr = internal global i32 0
@slow_death = external global i32
@.str.3 = [43 x i8] c"The system load is greater than 6.0 (%d)\0D\0A\00"
@.str.4 = [21 x i8] c"The game is dying.\0D\0A\00"
@.str.5 = [55 x i8] c"Game playing is no longer permitted on this machine:\0D\0A\00"
@.str.6 = [3 x i8] c"\0D\0A\00"
@shutdown = external global i32
@.str.7 = [55 x i8] c"Things look brighter now - you can continue playing.\0D\0A\00"
define void @gr(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [1024 x i8]
%5 = alloca i32
store i32 %0, i32* %2
store i8* null, i8** %3
store i32 0, i32* %5
%6 = call i32 (...) @load()
store i32 %6, i32* %5
%7 = icmp sge i32 %6, 6
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = call i8* (...) @nogames()
store i8* %9, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @slow_death
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %53
14: ; preds = %11, %8, %1
%15 = load i32, i32* %5
%16 = icmp sge i32 %15, 6
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%19 = load i32, i32* %5
%20 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %36
22: ; preds = %14
%23 = load i32, i32* @slow_death
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
br label %35
26: ; preds = %22
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%30 = load i8*, i8** %3
%31 = call i32 @strcat(i8* %29, i8* %30)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
br label %35
35: ; preds = %26, %25
br label %36
36: ; preds = %35, %17
%37 = load i32, i32* @gr.wnr
%38 = icmp slt i32 %37, 3
br i1 %38, label %39, label %45
39: ; preds = %36
%40 = load i32, i32* @gr.wnr
%41 = add nsw i32 %40, 1
store i32 %41, i32* @gr.wnr
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds [3 x i8*], [3 x i8*]* @gr.warnings, i64 0, i64 %42
%44 = load i8*, i8** %43
br label %52
45: ; preds = %36
%46 = load i32, i32* %5
%47 = icmp sge i32 %46, 6
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = load i32, i32* %2
store i32 0, i32* @gr.wnr
br label %51
50: ; preds = %45
store i32 1, i32* @shutdown
br label %51
51: ; preds = %50, %48
br label %52
52: ; preds = %51, %39
br label %63
53: ; preds = %11
%54 = call i64 (...) @workhours()
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %53
store i32 1, i32* @shutdown
br label %62
57: ; preds = %53
%58 = load i32, i32* @gr.wnr
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %57
store i32 0, i32* @gr.wnr
br label %61
61: ; preds = %60, %57
br label %62
62: ; preds = %61, %56
br label %63
63: ; preds = %62, %52
ret void
}

LLVM IR (-O2):
@reltable.gr = internal unnamed_addr constant [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([69 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.gr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([54 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.gr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([44 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.gr to i64)) to i32)]
@.str = [69 x i8] c"If things don't look better within 3 minutes, the game will pause.\0D\0A\00"
@.str.1 = [54 x i8] c"The game will close temporarily 2 minutes from now.\0D\0A\00"
@.str.2 = [44 x i8] c"WARNING: The game will close in 1 minute.\0D\0A\00"
@gr.wnr = internal unnamed_addr global i32 0
@slow_death = external global i32
@.str.3 = [43 x i8] c"The system load is greater than 6.0 (%d)\0D\0A\00"
@.str.4 = [21 x i8] c"The game is dying.\0D\0A\00"
@.str.5 = [55 x i8] c"Game playing is no longer permitted on this machine:\0D\0A\00"
@.str.6 = [3 x i8] c"\0D\0A\00"
@shutdown = external global i32
@.str.7 = [55 x i8] c"Things look brighter now - you can continue playing.\0D\0A\00"
define void @gr(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @load()
%5 = icmp sgt i32 %4, 5
br i1 %5, label %22, label %6
6: ; preds = %1
%7 = tail call i8* (...) @nogames()
%8 = icmp ne i8* %7, null
%9 = load i32, i32* @slow_death
%10 = icmp ne i32 %9, 0
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %12, label %34
12: ; preds = %6
%13 = icmp eq i32 %9, 0
br i1 %13, label %15, label %14
14: ; preds = %12
tail call void @send_to_all(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %19
15: ; preds = %12
%16 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 @strcat(i8* %3, i8* %7)
%18 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %19
19: ; preds = %14, %15
%20 = load i32, i32* @gr.wnr
%21 = icmp slt i32 %20, 3
br i1 %21, label %26, label %33
22: ; preds = %1
%23 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %4)
%24 = load i32, i32* @gr.wnr
%25 = icmp slt i32 %24, 3
br i1 %25, label %26, label %32
26: ; preds = %22, %19
%27 = phi i32 [ %24, %22 ], [ %20, %19 ]
%28 = add nsw i32 %27, 1
store i32 %28, i32* @gr.wnr
%29 = sext i32 %27 to i64
%30 = shl i64 %29, 2
%31 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.gr to i8*), i64 %30)
br label %42
32: ; preds = %22
store i32 0, i32* @gr.wnr
br label %42
33: ; preds = %19
store i32 1, i32* @shutdown
br label %42
34: ; preds = %6
%35 = tail call i64 (...) @workhours()
%36 = icmp eq i64 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %34
store i32 1, i32* @shutdown
br label %42
38: ; preds = %34
%39 = load i32, i32* @gr.wnr
%40 = icmp eq i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %38
tail call void @send_to_all(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* @gr.wnr
br label %42
42: ; preds = %37, %41, %38, %26, %33, %32
ret void
}