#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 */
struct casn {
  int dummy;
};

/* Variables and functions */
scalar_t__ read_casn_num(struct casn *, long *);
int diff_casn_num(struct casn *casnp, long val) {
  long tmp;
  if (read_casn_num(casnp, &tmp) < 0)
    return -2;
  if (tmp > val)
    return 1;
  else if (tmp < val)
    return -1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<diff_casn_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <read_casn_num@plt>
cmp    $0x0,%rax
jge    1143 <diff_casn_num+0x33>
movl   $0xfffffffe,-0x4(%rbp)
jmp    117e <diff_casn_num+0x6e>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jle    115d <diff_casn_num+0x4d>
movl   $0x1,-0x4(%rbp)
jmp    117e <diff_casn_num+0x6e>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1177 <diff_casn_num+0x67>
movl   $0xffffffff,-0x4(%rbp)
jmp    117e <diff_casn_num+0x6e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diff_casn_num>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rsi
call   1030 <read_casn_num@plt>
test   %rax,%rax
js     113d <diff_casn_num+0x2d>
mov    $0x1,%eax
cmp    %rbx,0x8(%rsp)
jg     1142 <diff_casn_num+0x32>
setl   %al
movzbl %al,%eax
neg    %eax
jmp    1142 <diff_casn_num+0x32>
mov    $0xfffffffe,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.casn = type { i32 }
define i32 @diff_casn_num(%struct.casn* %0, i64 %1) {
%3 = alloca i32
%4 = alloca %struct.casn*
%5 = alloca i64
%6 = alloca i64
store %struct.casn* %0, %struct.casn** %4
store i64 %1, i64* %5
%7 = load %struct.casn*, %struct.casn** %4
%8 = call i64 @read_casn_num(%struct.casn* %7, i64* %6)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -2, i32* %3
br label %22
11: ; preds = %2
%12 = load i64, i64* %6
%13 = load i64, i64* %5
%14 = icmp sgt i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 1, i32* %3
br label %22
16: ; preds = %11
%17 = load i64, i64* %6
%18 = load i64, i64* %5
%19 = icmp slt i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 -1, i32* %3
br label %22
21: ; preds = %16
store i32 0, i32* %3
br label %22
22: ; preds = %21, %20, %15, %10
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.casn = type { i32 }
define i32 @diff_casn_num(%struct.casn* %0, i64 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = call i64 @read_casn_num(%struct.casn* %0, i64* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %2
%8 = load i64, i64* %3
%9 = icmp sgt i64 %8, %1
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = icmp slt i64 %8, %1
%12 = sext i1 %11 to i32
br label %13
13: ; preds = %10, %7, %2
%14 = phi i32 [ -2, %2 ], [ 1, %7 ], [ %12, %10 ]
ret i32 %14
}