#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*/ fprintf(int /*<<< orphan*/, char *, int, int);
int midi_csum(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ update_ui_all(char *, char);
int receive_sndd(char *buf) {
  int checksum = midi_csum(&buf[7], 383);
  int expected = buf[7 + 383];
  if (checksum != expected) {
    fprintf(stderr,
            "Warning: Incorrect checksum in received data: "
            "calculated %d, should have been %d\n",
            checksum, expected);
    return -1;
  }
  update_ui_all(&buf[7], buf[6]);
  return 0;
}


x86 assembly (clang, -O0):
<receive_sndd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
mov    $0x17f,%esi
call   1050 <midi_csum@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x186(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1192 <receive_sndd+0x62>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe7f(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ae <receive_sndd+0x7e>
mov    -0x10(%rbp),%rdi
add    $0x7,%rdi
mov    -0x10(%rbp),%rax
movsbl 0x6(%rax),%esi
call   1030 <update_ui_all@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<receive_sndd>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0x7(%rdi),%r14
mov    %r14,%rdi
mov    $0x17f,%esi
call   1050 <midi_csum@plt>
movsbl 0x186(%rbx),%ecx
cmp    %ecx,%eax
jne    1163 <receive_sndd+0x33>
movsbl 0x6(%rbx),%esi
mov    %r14,%rdi
call   1030 <update_ui_all@plt>
xor    %eax,%eax
jmp    117f <receive_sndd+0x4f>
mov    0x2e76(%rip),%rdx
mov    (%rdx),%edi
lea    0xe8d(%rip),%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [82 x i8] c"Warning: Incorrect checksum in received data: calculated %d, should have been %d\0A\00"
define i32 @receive_sndd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 7
%8 = call i32 @midi_csum(i8* %7, i32 383)
store i32 %8, i32* %4
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 390
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
store i32 %12, i32* %5
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = icmp ne i32 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %1
%17 = load i32, i32* @stderr
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
store i32 -1, i32* %2
br label %28
21: ; preds = %1
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 7
%24 = load i8*, i8** %3
%25 = getelementptr inbounds i8, i8* %24, i64 6
%26 = load i8, i8* %25
%27 = call i32 @update_ui_all(i8* %23, i8 signext %26)
store i32 0, i32* %2
br label %28
28: ; preds = %21, %16
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [82 x i8] c"Warning: Incorrect checksum in received data: calculated %d, should have been %d\0A\00"
define i32 @receive_sndd(i8* %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 7
%3 = tail call i32 @midi_csum(i8* %2, i32 383)
%4 = getelementptr inbounds i8, i8* %0, i64 390
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = icmp eq i32 %3, %6
br i1 %7, label %11, label %8
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %6)
br label %15
11: ; preds = %1
%12 = getelementptr inbounds i8, i8* %0, i64 6
%13 = load i8, i8* %12
%14 = tail call i32 @update_ui_all(i8* %2, i8 signext %13)
br label %15
15: ; preds = %11, %8
%16 = phi i32 [ -1, %8 ], [ 0, %11 ]
ret i32 %16
}