#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 */
void *ArgNum();
int /*<<< orphan*/ Log(char *);
int /*<<< orphan*/ Me();
int /*<<< orphan*/ SendItem(int /*<<< orphan*/, char *);
int /*<<< orphan*/ SetFlag(int, unsigned short);
int rand();
void Act_Random(void) {
  int a = ArgNum();
  unsigned int b = ArgNum();
  unsigned int b2;
  unsigned short v;
regen:
  b2 = b;
  v = rand() % 32768;
  if (b == 0) {
    SendItem(Me(), "Invalid Random Range.\n");
    Log("Invalid Random Range.\n");
    return;
  }
  b = 32768 / b;
  if (b == 0) {
    SendItem(Me(), "Invalid Random Range.\n");
    Log("Random Too Large.\n");
    return;
  }
  if (v / b == b2) {
    b = b2;
    goto regen;
  }
  SetFlag(a, (v / b));
}


x86 assembly (clang, -O0):
<Act_Random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <ArgNum@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1060 <ArgNum@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x8000,%ecx
cltd
idiv   %ecx
mov    %dx,%ax
mov    %ax,-0xe(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11c8 <Act_Random+0x68>
mov    $0x0,%al
call   1070 <Me@plt>
mov    %eax,%edi
lea    0xe4e(%rip),%rsi
call   1040 <SendItem@plt>
lea    0xe42(%rip),%rdi
call   1050 <Log@plt>
jmp    1236 <Act_Random+0xd6>
mov    $0x8000,%eax
xor    %edx,%edx
divl   -0x8(%rbp)
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1205 <Act_Random+0xa5>
mov    $0x0,%al
call   1070 <Me@plt>
mov    %eax,%edi
lea    0xe11(%rip),%rsi
call   1040 <SendItem@plt>
lea    0xe1c(%rip),%rdi
call   1050 <Log@plt>
jmp    1236 <Act_Random+0xd6>
movzwl -0xe(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
cmp    -0xc(%rbp),%eax
jne    1222 <Act_Random+0xc2>
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    117c <Act_Random+0x1c>
mov    -0x4(%rbp),%edi
movzwl -0xe(%rbp),%eax
xor    %edx,%edx
divl   -0x8(%rbp)
movzwl %ax,%esi
call   1030 <SetFlag@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Act_Random>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <ArgNum@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1060 <ArgNum@plt>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <rand@plt>
mov    %eax,%ecx
lea    0x7fff(%rcx),%eax
test   %ecx,%ecx
cmovns %ecx,%eax
test   %ebx,%ebx
je     11cf <Act_Random+0x6f>
cmp    $0x8001,%ebx
jae    11ec <Act_Random+0x8c>
and    $0xffff8000,%eax
sub    %eax,%ecx
mov    $0x8000,%ax
xor    %edx,%edx
div    %bx
mov    %eax,%esi
mov    %ecx,%eax
xor    %edx,%edx
div    %si
movzwl %ax,%esi
cmp    %ebx,%esi
je     1180 <Act_Random+0x20>
mov    %r14d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <SetFlag@plt>
xor    %eax,%eax
call   1070 <Me@plt>
lea    0xe23(%rip),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
call   1040 <SendItem@plt>
mov    %rbx,%rdi
jmp    1208 <Act_Random+0xa8>
xor    %eax,%eax
call   1070 <Me@plt>
lea    0xe06(%rip),%rsi
mov    %eax,%edi
call   1040 <SendItem@plt>
lea    0xe0f(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <Log@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Invalid Random Range.\0A\00"
@.str.1 = [19 x i8] c"Random Too Large.\0A\00"
define void @Act_Random() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i16
%5 = call i8* (...) @ArgNum()
%6 = ptrtoint i8* %5 to i32
store i32 %6, i32* %1
%7 = call i8* (...) @ArgNum()
%8 = ptrtoint i8* %7 to i32
store i32 %8, i32* %2
br label %9
9: ; preds = %36, %0
%10 = load i32, i32* %2
store i32 %10, i32* %3
%11 = call i32 (...) @rand()
%12 = srem i32 %11, 32768
%13 = trunc i32 %12 to i16
store i16 %13, i16* %4
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = call i32 (...) @Me()
%18 = call i32 @SendItem(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%19 = call i32 @Log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %46
20: ; preds = %9
%21 = load i32, i32* %2
%22 = udiv i32 32768, %21
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = call i32 (...) @Me()
%27 = call i32 @SendItem(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @Log(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %46
29: ; preds = %20
%30 = load i16, i16* %4
%31 = zext i16 %30 to i32
%32 = load i32, i32* %2
%33 = udiv i32 %31, %32
%34 = load i32, i32* %3
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = load i32, i32* %3
store i32 %37, i32* %2
br label %9
38: ; preds = %29
%39 = load i32, i32* %1
%40 = load i16, i16* %4
%41 = zext i16 %40 to i32
%42 = load i32, i32* %2
%43 = udiv i32 %41, %42
%44 = trunc i32 %43 to i16
%45 = call i32 @SetFlag(i32 %39, i16 zeroext %44)
br label %46
46: ; preds = %38, %25, %16
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"Invalid Random Range.\0A\00"
@.str.1 = [19 x i8] c"Random Too Large.\0A\00"
define void @Act_Random() {
%1 = tail call i8* (...) @ArgNum()
%2 = ptrtoint i8* %1 to i64
%3 = trunc i64 %2 to i32
%4 = tail call i8* (...) @ArgNum()
%5 = ptrtoint i8* %4 to i64
%6 = trunc i64 %5 to i32
%7 = icmp eq i32 %6, 0
%8 = icmp ugt i32 %6, 32768
%9 = trunc i64 %5 to i16
br label %10
10: ; preds = %22, %0
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 32768
br i1 %7, label %13, label %17
13: ; preds = %10
%14 = tail call i32 (...) @Me()
%15 = tail call i32 @SendItem(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @Log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %30
17: ; preds = %10
br i1 %8, label %18, label %22
18: ; preds = %17
%19 = tail call i32 (...) @Me()
%20 = tail call i32 @SendItem(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @Log(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %30
22: ; preds = %17
%23 = udiv i16 -32768, %9
%24 = trunc i32 %12 to i16
%25 = udiv i16 %24, %23
%26 = zext i16 %25 to i32
%27 = icmp eq i32 %26, %6
br i1 %27, label %10, label %28
28: ; preds = %22
%29 = tail call i32 @SetFlag(i32 %3, i16 zeroext %25)
br label %30
30: ; preds = %28, %18, %13
ret void
}