#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*/ add_job();
int /*<<< orphan*/ add_res();
int random();
int /*<<< orphan*/ remove_done_jobs();
int /*<<< orphan*/ remove_leaving_resources();
void add_remove() {
  static int begin = 1;
  int i;
  if (begin) {
    for (i = 1; i <= 5; ++i)
      add_res();
    begin = 0;
  }
  remove_done_jobs();
  remove_leaving_resources();
  i = 1 + (random() % 1000);
  if (i <= 50)
    add_res();
  else if (i > 800)
    add_job();
}


x86 assembly (clang, -O0):
<add_remove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2ee9(%rip)
je     1195 <add_remove+0x45>
movl   $0x1,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jg     118b <add_remove+0x3b>
mov    $0x0,%al
call   1050 <add_res@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    116c <add_remove+0x1c>
movl   $0x0,0x2eb3(%rip)
mov    $0x0,%al
call   1060 <remove_done_jobs@plt>
mov    $0x0,%al
call   1040 <remove_leaving_resources@plt>
mov    $0x0,%al
call   1070 <random@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x4(%rbp)
cmpl   $0x32,-0x4(%rbp)
jg     11ce <add_remove+0x7e>
mov    $0x0,%al
call   1050 <add_res@plt>
jmp    11e7 <add_remove+0x97>
cmpl   $0x320,-0x4(%rbp)
jle    11e2 <add_remove+0x92>
mov    $0x0,%al
call   1030 <add_job@plt>
jmp    11e7 <add_remove+0x97>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_remove>:
push   %rax
cmpb   $0x0,0x2ef4(%rip)
jne    1184 <add_remove+0x34>
xor    %eax,%eax
call   1050 <add_res@plt>
xor    %eax,%eax
call   1050 <add_res@plt>
xor    %eax,%eax
call   1050 <add_res@plt>
xor    %eax,%eax
call   1050 <add_res@plt>
xor    %eax,%eax
call   1050 <add_res@plt>
movb   $0x1,0x2ec8(%rip)
xor    %eax,%eax
call   1060 <remove_done_jobs@plt>
xor    %eax,%eax
call   1040 <remove_leaving_resources@plt>
xor    %eax,%eax
call   1070 <random@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x31,%eax
jg     11c4 <add_remove+0x74>
xor    %eax,%eax
pop    %rcx
jmp    1050 <add_res@plt>
cmp    $0x320,%eax
jb     11d3 <add_remove+0x83>
xor    %eax,%eax
pop    %rcx
jmp    1030 <add_job@plt>
pop    %rax
ret

LLVM IR (-O0):
@add_remove.begin = internal global i32 1
define void @add_remove() {
%1 = alloca i32
%2 = load i32, i32* @add_remove.begin
%3 = icmp ne i32 %2, 0
br i1 %3, label %4, label %14
4: ; preds = %0
store i32 1, i32* %1
br label %5
5: ; preds = %10, %4
%6 = load i32, i32* %1
%7 = icmp sle i32 %6, 5
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = call i32 (...) @add_res()
br label %10
10: ; preds = %8
%11 = load i32, i32* %1
%12 = add nsw i32 %11, 1
store i32 %12, i32* %1
br label %5
13: ; preds = %5
store i32 0, i32* @add_remove.begin
br label %14
14: ; preds = %13, %0
%15 = call i32 (...) @remove_done_jobs()
%16 = call i32 (...) @remove_leaving_resources()
%17 = call i32 (...) @random()
%18 = srem i32 %17, 1000
%19 = add nsw i32 1, %18
store i32 %19, i32* %1
%20 = load i32, i32* %1
%21 = icmp sle i32 %20, 50
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 (...) @add_res()
br label %30
24: ; preds = %14
%25 = load i32, i32* %1
%26 = icmp sgt i32 %25, 800
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 (...) @add_job()
br label %29
29: ; preds = %27, %24
br label %30
30: ; preds = %29, %22
ret void
}

LLVM IR (-O2):
@add_remove.begin = internal unnamed_addr global i1 false
define void @add_remove() {
%1 = load i1, i1* @add_remove.begin
br i1 %1, label %8, label %2
2: ; preds = %0
%3 = tail call i32 (...) @add_res()
%4 = tail call i32 (...) @add_res()
%5 = tail call i32 (...) @add_res()
%6 = tail call i32 (...) @add_res()
%7 = tail call i32 (...) @add_res()
store i1 true, i1* @add_remove.begin
br label %8
8: ; preds = %2, %0
%9 = tail call i32 (...) @remove_done_jobs()
%10 = tail call i32 (...) @remove_leaving_resources()
%11 = tail call i32 (...) @random()
%12 = srem i32 %11, 1000
%13 = icmp slt i32 %12, 50
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = tail call i32 (...) @add_res()
br label %20
16: ; preds = %8
%17 = icmp ugt i32 %12, 799
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail call i32 (...) @add_job()
br label %20
20: ; preds = %16, %18, %14
ret void
}