#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 rand();
int rand_age() {
  int a = rand() % 1001;
  if (a <= 840)
    return a / 12;
  else {
    int r = (a * a * 96 * 8 - (a * 97) * 1536 * 8 + 3675 * 1536 * 96) /
            (1536 * 96 * 8);
    return r;
  }
}


x86 assembly (clang, -O0):
<rand_age>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3e9,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
cmpl   $0x348,-0x8(%rbp)
jg     114a <rand_age+0x3a>
mov    -0x8(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
jmp    117c <rand_age+0x6c>
mov    -0x8(%rbp),%eax
imul   -0x8(%rbp),%eax
imul   $0x60,%eax,%eax
shl    $0x3,%eax
imul   $0x61,-0x8(%rbp),%ecx
imul   $0x600,%ecx,%ecx
shl    $0x3,%ecx
sub    %ecx,%eax
add    $0x204cc000,%eax
mov    $0x120000,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_age>:
push   %rax
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x4178749f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x28,%rcx
add    %edx,%ecx
imul   $0x3e9,%ecx,%ecx
sub    %ecx,%eax
cmp    $0x348,%eax
jg     1150 <rand_age+0x40>
cwtl
imul   $0x2aab,%eax,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x11,%eax
add    %ecx,%eax
pop    %rcx
ret
lea    (%rax,%rax,2),%ecx
shl    $0x8,%ecx
add    $0xffedd000,%ecx
imul   %eax,%ecx
add    $0x204cc000,%ecx
movslq %ecx,%rax
imul   $0x38e38e39,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x32,%rax
add    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @rand_age() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @rand()
%5 = srem i32 %4, 1001
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp sle i32 %6, 840
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* %2
%10 = sdiv i32 %9, 12
store i32 %10, i32* %1
br label %25
11: ; preds = %0
%12 = load i32, i32* %2
%13 = load i32, i32* %2
%14 = mul nsw i32 %12, %13
%15 = mul nsw i32 %14, 96
%16 = mul nsw i32 %15, 8
%17 = load i32, i32* %2
%18 = mul nsw i32 %17, 97
%19 = mul nsw i32 %18, 1536
%20 = mul nsw i32 %19, 8
%21 = sub nsw i32 %16, %20
%22 = add nsw i32 %21, 541900800
%23 = sdiv i32 %22, 1179648
store i32 %23, i32* %3
%24 = load i32, i32* %3
store i32 %24, i32* %1
br label %25
25: ; preds = %11, %8
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
define i32 @rand_age() {
%1 = tail call i32 (...) @rand()
%2 = srem i32 %1, 1001
%3 = icmp slt i32 %2, 841
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = trunc i32 %2 to i16
%6 = sdiv i16 %5, 12
%7 = sext i16 %6 to i32
br label %14
8: ; preds = %0
%9 = mul nuw nsw i32 %2, 768
%10 = add nuw nsw i32 %9, -1191936
%11 = mul nsw i32 %10, %2
%12 = add nsw i32 %11, 541900800
%13 = sdiv i32 %12, 1179648
br label %14
14: ; preds = %8, %4
%15 = phi i32 [ %7, %4 ], [ %13, %8 ]
ret i32 %15
}