#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 determine_term(int difficulty) {
  int pos_neg = 0, term = 0;
  if (difficulty == 3) {
    term = rand() % 9;
  } else if (difficulty == 4) {
    term = rand() % 99;
  } else {
    term = rand() % 999 + 10;
  }
  pos_neg = rand() % 2;
  if (pos_neg == 1) {
    term = -term;
  }
  return term;
}


x86 assembly (clang, -O0):
<determine_term>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0x4(%rbp)
jne    114a <determine_term+0x3a>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x9,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
jmp    1185 <determine_term+0x75>
cmpl   $0x4,-0x4(%rbp)
jne    116b <determine_term+0x5b>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x63,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
jmp    1180 <determine_term+0x70>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3e7,%ecx
cltd
idiv   %ecx
add    $0xa,%edx
mov    %edx,-0xc(%rbp)
jmp    1185 <determine_term+0x75>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11a9 <determine_term+0x99>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<determine_term>:
push   %rbx
xor    %eax,%eax
cmp    $0x4,%edi
je     1140 <determine_term+0x30>
cmp    $0x3,%edi
jne    1166 <determine_term+0x56>
call   1030 <rand@plt>
movslq %eax,%rbx
imul   $0x38e38e39,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
lea    (%rax,%rax,8),%eax
sub    %eax,%ebx
jmp    1192 <determine_term+0x82>
call   1030 <rand@plt>
movslq %eax,%rbx
imul   $0xffffffffa57eb503,%rbx,%rax
shr    $0x20,%rax
add    %ebx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0x6,%eax
add    %ecx,%eax
imul   $0x63,%eax,%eax
sub    %eax,%ebx
jmp    1192 <determine_term+0x82>
call   1030 <rand@plt>
cltq
imul   $0xffffffff83340521,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x9,%ecx
add    %edx,%ecx
imul   $0x3e7,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%ebx
add    $0xa,%ebx
xor    %eax,%eax
call   1030 <rand@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
mov    %ebx,%ecx
neg    %ecx
cmp    $0x1,%eax
cmovne %ebx,%ecx
mov    %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @determine_term(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 3
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 9
store i32 %9, i32* %4
br label %21
10: ; preds = %1
%11 = load i32, i32* %2
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 99
store i32 %15, i32* %4
br label %20
16: ; preds = %10
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 999
%19 = add nsw i32 %18, 10
store i32 %19, i32* %4
br label %20
20: ; preds = %16, %13
br label %21
21: ; preds = %20, %7
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 2
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* %4
%28 = sub nsw i32 0, %27
store i32 %28, i32* %4
br label %29
29: ; preds = %26, %21
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @determine_term(i32 %0) {
switch i32 %0, label %8 [
i32 3, label %2
i32 4, label %5
]
2: ; preds = %1
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 9
br label %12
5: ; preds = %1
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 99
br label %12
8: ; preds = %1
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 999
%11 = add nsw i32 %10, 10
br label %12
12: ; preds = %5, %8, %2
%13 = phi i32 [ %4, %2 ], [ %7, %5 ], [ %11, %8 ]
%14 = tail call i32 (...) @rand()
%15 = srem i32 %14, 2
%16 = icmp eq i32 %15, 1
%17 = sub nsw i32 0, %13
%18 = select i1 %16, i32 %17, i32 %13
ret i32 %18
}