#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 game_random_int();
int calc_height_displacement(int avg, int base, int offset) {
  int r = game_random_int();
  int h = ((r * base) >> 16) - offset + avg;
  return (((0) > ((((h) < (250)) ? (h) : (250))))
              ? (0)
              : ((((h) < (250)) ? (h) : (250))));
}


x86 assembly (clang, -O0):
<calc_height_displacement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    $0x0,%al
call   1030 <game_random_int@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x8(%rbp),%eax
sar    $0x10,%eax
sub    -0xc(%rbp),%eax
add    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xfa,-0x14(%rbp)
jge    1156 <calc_height_displacement+0x46>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1163 <calc_height_displacement+0x53>
mov    $0xfa,%eax
mov    %eax,-0x18(%rbp)
jmp    1163 <calc_height_displacement+0x53>
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jle    117a <calc_height_displacement+0x6a>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a5 <calc_height_displacement+0x95>
cmpl   $0xfa,-0x14(%rbp)
jge    1192 <calc_height_displacement+0x82>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    119f <calc_height_displacement+0x8f>
mov    $0xfa,%eax
mov    %eax,-0x20(%rbp)
jmp    119f <calc_height_displacement+0x8f>
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_height_displacement>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%ebp
mov    %edi,%r14d
xor    %r15d,%r15d
xor    %eax,%eax
call   1030 <game_random_int@plt>
imul   %ebp,%eax
sar    $0x10,%eax
sub    %ebx,%eax
add    %r14d,%eax
cmp    $0xfa,%eax
mov    $0xfa,%ecx
cmovge %ecx,%eax
test   %eax,%eax
cmovs  %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @calc_height_displacement(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = call i32 (...) @game_random_int()
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = load i32, i32* %5
%12 = mul nsw i32 %10, %11
%13 = ashr i32 %12, 16
%14 = load i32, i32* %6
%15 = sub nsw i32 %13, %14
%16 = load i32, i32* %4
%17 = add nsw i32 %15, %16
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp slt i32 %18, 250
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = load i32, i32* %8
br label %23
22: ; preds = %3
br label %23
23: ; preds = %22, %20
%24 = phi i32 [ %21, %20 ], [ 250, %22 ]
%25 = icmp sgt i32 0, %24
br i1 %25, label %26, label %27
26: ; preds = %23
br label %35
27: ; preds = %23
%28 = load i32, i32* %8
%29 = icmp slt i32 %28, 250
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i32, i32* %8
br label %33
32: ; preds = %27
br label %33
33: ; preds = %32, %30
%34 = phi i32 [ %31, %30 ], [ 250, %32 ]
br label %35
35: ; preds = %33, %26
%36 = phi i32 [ 0, %26 ], [ %34, %33 ]
ret i32 %36
}

LLVM IR (-O2):
define i32 @calc_height_displacement(i32 %0, i32 %1, i32 %2) {
%4 = tail call i32 (...) @game_random_int()
%5 = mul nsw i32 %4, %1
%6 = ashr i32 %5, 16
%7 = sub nsw i32 %6, %2
%8 = add nsw i32 %7, %0
%9 = icmp slt i32 %8, 250
%10 = select i1 %9, i32 %8, i32 250
%11 = icmp sgt i32 %10, 0
%12 = select i1 %11, i32 %10, i32 0
ret i32 %12
}