#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*/ printf(char *, int, int);
int OperandValue(int operand, int value) {
  int retval;
  static int number;
  static int order;
  static int previous;
  if (operand == (-9)) {
    number = 0;
    order = 0;
    previous = 0;
    retval = 0;
  } else if (operand == (-99)) {
    retval = number;
  } else if (operand == (-999)) {
    if (order == (number - 1)) {
      retval = 1;
    } else if ((-order) == (number - 1)) {
      retval = -1;
    } else {
      retval = 0;
    }
  } else {
    printf("   Operand %d: value %d\n", operand, value);
    number++;
    if (previous != 0) {
      if (previous < operand) {
        order++;
      } else {
        order--;
      }
    }
    previous = operand;
    retval = value;
  }
  return retval;
}


x86 assembly (clang, -O0):
<OperandValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0xfffffff7,-0x4(%rbp)
jne    1152 <OperandValue+0x42>
movl   $0x0,0x2efa(%rip)
movl   $0x0,0x2ef4(%rip)
movl   $0x0,0x2eee(%rip)
movl   $0x0,-0xc(%rbp)
jmp    124e <OperandValue+0x13e>
cmpl   $0xffffff9d,-0x4(%rbp)
jne    116a <OperandValue+0x5a>
mov    0x2eca(%rip),%eax
mov    %eax,-0xc(%rbp)
jmp    1249 <OperandValue+0x139>
cmpl   $0xfffffc19,-0x4(%rbp)
jne    11d0 <OperandValue+0xc0>
mov    0x2eb3(%rip),%eax
mov    0x2ea9(%rip),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    119a <OperandValue+0x8a>
movl   $0x1,-0xc(%rbp)
jmp    11cb <OperandValue+0xbb>
xor    %eax,%eax
sub    0x2e8e(%rip),%eax
mov    0x2e84(%rip),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11bf <OperandValue+0xaf>
movl   $0xffffffff,-0xc(%rbp)
jmp    11c6 <OperandValue+0xb6>
movl   $0x0,-0xc(%rbp)
jmp    11cb <OperandValue+0xbb>
jmp    1244 <OperandValue+0x134>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e44(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e3b(%rip)
cmpl   $0x0,0x2e3c(%rip)
je     1235 <OperandValue+0x125>
mov    0x2e30(%rip),%eax
cmp    -0x4(%rbp),%eax
jge    1221 <OperandValue+0x111>
mov    0x2e1d(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e14(%rip)
jmp    1230 <OperandValue+0x120>
mov    0x2e09(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2e00(%rip)
jmp    1235 <OperandValue+0x125>
mov    -0x4(%rbp),%eax
mov    %eax,0x2df6(%rip)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1249 <OperandValue+0x139>
jmp    124e <OperandValue+0x13e>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OperandValue>:
push   %rbp
push   %rbx
push   %rax
cmp    $0xfffffc19,%edi
je     1151 <OperandValue+0x41>
mov    %edi,%ebp
cmp    $0xffffff9d,%edi
je     1149 <OperandValue+0x39>
cmp    $0xfffffff7,%ebp
jne    1174 <OperandValue+0x64>
movl   $0x0,0x2efb(%rip)
movl   $0x0,0x2ef5(%rip)
movl   $0x0,0x2eef(%rip)
xor    %ebx,%ebx
jmp    11b6 <OperandValue+0xa6>
mov    0x2edd(%rip),%ebx
jmp    11b6 <OperandValue+0xa6>
mov    0x2ed9(%rip),%eax
mov    0x2ecf(%rip),%ecx
add    $0xffffffff,%ecx
mov    $0x1,%ebx
cmp    %ecx,%eax
je     11b6 <OperandValue+0xa6>
xor    %ebx,%ebx
add    %eax,%ecx
sete   %bl
neg    %ebx
jmp    11b6 <OperandValue+0xa6>
mov    %esi,%ebx
lea    0xe83(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1030 <printf@plt>
addl   $0x1,0x2e9f(%rip)
mov    0x2ea1(%rip),%eax
test   %eax,%eax
je     11b0 <OperandValue+0xa0>
xor    %ecx,%ecx
cmp    %ebp,%eax
setl   %cl
mov    0x2e8c(%rip),%eax
lea    (%rax,%rcx,2),%eax
add    $0xffffffff,%eax
mov    %eax,0x2e80(%rip)
mov    %ebp,0x2e7e(%rip)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@OperandValue.number = internal global i32 0
@OperandValue.order = internal global i32 0
@OperandValue.previous = internal global i32 0
@.str = [25 x i8] c" Operand %d: value %d\0A\00"
define i32 @OperandValue(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -9
br i1 %7, label %8, label %9
8: ; preds = %2
store i32 0, i32* @OperandValue.number
store i32 0, i32* @OperandValue.order
store i32 0, i32* @OperandValue.previous
store i32 0, i32* %5
br label %57
9: ; preds = %2
%10 = load i32, i32* %3
%11 = icmp eq i32 %10, -99
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = load i32, i32* @OperandValue.number
store i32 %13, i32* %5
br label %56
14: ; preds = %9
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, -999
br i1 %16, label %17, label %33
17: ; preds = %14
%18 = load i32, i32* @OperandValue.order
%19 = load i32, i32* @OperandValue.number
%20 = sub nsw i32 %19, 1
%21 = icmp eq i32 %18, %20
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 1, i32* %5
br label %32
23: ; preds = %17
%24 = load i32, i32* @OperandValue.order
%25 = sub nsw i32 0, %24
%26 = load i32, i32* @OperandValue.number
%27 = sub nsw i32 %26, 1
%28 = icmp eq i32 %25, %27
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 -1, i32* %5
br label %31
30: ; preds = %23
store i32 0, i32* %5
br label %31
31: ; preds = %30, %29
br label %32
32: ; preds = %31, %22
br label %55
33: ; preds = %14
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %34, i32 %35)
%37 = load i32, i32* @OperandValue.number
%38 = add nsw i32 %37, 1
store i32 %38, i32* @OperandValue.number
%39 = load i32, i32* @OperandValue.previous
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %52
41: ; preds = %33
%42 = load i32, i32* @OperandValue.previous
%43 = load i32, i32* %3
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* @OperandValue.order
%47 = add nsw i32 %46, 1
store i32 %47, i32* @OperandValue.order
br label %51
48: ; preds = %41
%49 = load i32, i32* @OperandValue.order
%50 = add nsw i32 %49, -1
store i32 %50, i32* @OperandValue.order
br label %51
51: ; preds = %48, %45
br label %52
52: ; preds = %51, %33
%53 = load i32, i32* %3
store i32 %53, i32* @OperandValue.previous
%54 = load i32, i32* %4
store i32 %54, i32* %5
br label %55
55: ; preds = %52, %32
br label %56
56: ; preds = %55, %12
br label %57
57: ; preds = %56, %8
%58 = load i32, i32* %5
ret i32 %58
}

LLVM IR (-O2):
@OperandValue.number = internal unnamed_addr global i32 0
@OperandValue.order = internal unnamed_addr global i32 0
@OperandValue.previous = internal unnamed_addr global i32 0
@.str = [25 x i8] c" Operand %d: value %d\0A\00"
define i32 @OperandValue(i32 %0, i32 %1) {
switch i32 %0, label %15 [
i32 -9, label %3
i32 -99, label %4
i32 -999, label %6
]
3: ; preds = %2
store i32 0, i32* @OperandValue.number
store i32 0, i32* @OperandValue.order
store i32 0, i32* @OperandValue.previous
br label %27
4: ; preds = %2
%5 = load i32, i32* @OperandValue.number
br label %27
6: ; preds = %2
%7 = load i32, i32* @OperandValue.order
%8 = load i32, i32* @OperandValue.number
%9 = add nsw i32 %8, -1
%10 = icmp eq i32 %7, %9
br i1 %10, label %27, label %11
11: ; preds = %6
%12 = sub nsw i32 0, %7
%13 = icmp eq i32 %9, %12
%14 = sext i1 %13 to i32
br label %27
15: ; preds = %2
%16 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%17 = load i32, i32* @OperandValue.number
%18 = add nsw i32 %17, 1
store i32 %18, i32* @OperandValue.number
%19 = load i32, i32* @OperandValue.previous
%20 = icmp eq i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %15
%22 = icmp slt i32 %19, %0
%23 = load i32, i32* @OperandValue.order
%24 = select i1 %22, i32 1, i32 -1
%25 = add nsw i32 %23, %24
store i32 %25, i32* @OperandValue.order
br label %26
26: ; preds = %21, %15
store i32 %0, i32* @OperandValue.previous
br label %27
27: ; preds = %11, %6, %4, %26, %3
%28 = phi i32 [ 0, %3 ], [ %5, %4 ], [ %1, %26 ], [ 1, %6 ], [ %14, %11 ]
ret i32 %28
}