#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*/ getchecksum(unsigned char *, unsigned char *, int);
int checksum(unsigned char *buf, int len) {
  unsigned char cs[2];
  getchecksum(cs, buf, len - 2);
  if (cs[0] == buf[len - 2] && cs[1] == buf[len - 1])
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x16(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
sub    $0x2,%edx
call   1030 <getchecksum@plt>
movzbl -0x16(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x2,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1178 <checksum+0x68>
movzbl -0x15(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    1178 <checksum+0x68>
movl   $0x1,-0x4(%rbp)
jmp    117f <checksum+0x6f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checksum>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movslq %esi,%rbx
lea    -0x2(%rbx),%rdx
lea    0x6(%rsp),%rdi
mov    %r14,%rsi
call   1030 <getchecksum@plt>
mov    0x6(%rsp),%al
cmp    -0x2(%r14,%rbx,1),%al
jne    1146 <checksum+0x36>
mov    0x7(%rsp),%cl
mov    $0x1,%eax
cmp    -0x1(%rbx,%r14,1),%cl
je     1148 <checksum+0x38>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @checksum(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [2 x i8]
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%8 = load i8*, i8** %4
%9 = load i32, i32* %5
%10 = sub nsw i32 %9, 2
%11 = call i32 @getchecksum(i8* %7, i8* %8, i32 %10)
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = load i8*, i8** %4
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 2
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = icmp eq i32 %14, %21
br i1 %22, label %23, label %36
23: ; preds = %2
%24 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = load i8*, i8** %4
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = icmp eq i32 %26, %33
br i1 %34, label %35, label %36
35: ; preds = %23
store i32 1, i32* %3
br label %37
36: ; preds = %23, %2
store i32 0, i32* %3
br label %37
37: ; preds = %36, %35
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
define i32 @checksum(i8* %0, i32 %1) {
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = add nsw i32 %1, -2
%6 = call i32 @getchecksum(i8* %4, i8* %0, i32 %5)
%7 = load i8, i8* %4
%8 = sext i32 %5 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %7, %10
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
%14 = load i8, i8* %13
%15 = add nsw i32 %1, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %14, %18
br i1 %19, label %21, label %20
20: ; preds = %12, %2
br label %21
21: ; preds = %12, %20
%22 = phi i32 [ 0, %20 ], [ 1, %12 ]
ret i32 %22
}