#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 */
unsigned int d_gl_calc_crc16m(unsigned char *, int);
int d_gl_checkpin(unsigned int sno, unsigned int pin) {
  unsigned char buf[10];
  unsigned int crc;
  buf[0] = (unsigned char)(sno >> 16);
  buf[1] = (unsigned char)(sno >> 8);
  buf[2] = (unsigned char)(sno);
  crc = d_gl_calc_crc16m(buf, 3);
  if (crc == pin)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<d_gl_checkpin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x10,%eax
mov    %al,-0x16(%rbp)
mov    -0x8(%rbp),%eax
shr    $0x8,%eax
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%eax
mov    %al,-0x14(%rbp)
lea    -0x16(%rbp),%rdi
mov    $0x3,%esi
call   1030 <d_gl_calc_crc16m@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jne    115f <d_gl_checkpin+0x4f>
movl   $0x1,-0x4(%rbp)
jmp    1166 <d_gl_checkpin+0x56>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d_gl_checkpin>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%eax
mov    %edi,%ecx
shr    $0x10,%ecx
mov    %cl,0x6(%rsp)
mov    %ah,0x7(%rsp)
mov    %al,0x8(%rsp)
lea    0x6(%rsp),%rdi
mov    $0x3,%esi
call   1030 <d_gl_calc_crc16m@plt>
xor    %ecx,%ecx
cmp    %ebx,%eax
sete   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @d_gl_checkpin(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i8]
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = lshr i32 %8, 16
%10 = trunc i32 %9 to i8
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
store i8 %10, i8* %11
%12 = load i32, i32* %4
%13 = lshr i32 %12, 8
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 1
store i8 %14, i8* %15
%16 = load i32, i32* %4
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 2
store i8 %17, i8* %18
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%20 = call i32 @d_gl_calc_crc16m(i8* %19, i32 3)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = load i32, i32* %5
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %2
store i32 1, i32* %3
br label %26
25: ; preds = %2
store i32 0, i32* %3
br label %26
26: ; preds = %25, %24
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @d_gl_checkpin(i32 %0, i32 %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = lshr i32 %0, 16
%6 = trunc i32 %5 to i8
store i8 %6, i8* %4
%7 = lshr i32 %0, 8
%8 = trunc i32 %7 to i8
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 1
store i8 %8, i8* %9
%10 = trunc i32 %0 to i8
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 2
store i8 %10, i8* %11
%12 = call i32 @d_gl_calc_crc16m(i8* %4, i32 3)
%13 = icmp eq i32 %12, %1
%14 = zext i1 %13 to i32
ret i32 %14
}