#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*/ error(char *);
int handle_ack(char *buffer, int buffer_size, int last_block) {
  int block_nb = 0;
  if (buffer_size != 4)
    error("Wrong ACK received");
  block_nb = (unsigned char)buffer[2] * 256 + (unsigned char)buffer[3];
  if (block_nb != last_block)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<handle_ack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x14(%rbp)
je     113f <handle_ack+0x2f>
lea    0xec6(%rip),%rdi
call   1030 <error@plt>
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
shl    $0x8,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     116f <handle_ack+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1176 <handle_ack+0x66>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_ack>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
cmp    $0x4,%esi
je     1129 <handle_ack+0x19>
lea    0xedc(%rip),%rdi
call   1030 <error@plt>
movzwl 0x2(%rbx),%ecx
shl    $0x10,%ecx
bswap  %ecx
xor    %eax,%eax
cmp    %ebp,%ecx
setne  %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Wrong ACK received\00"
define i32 @handle_ack(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = load i8*, i8** %5
%15 = getelementptr inbounds i8, i8* %14, i64 2
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = mul nsw i32 %17, 256
%19 = load i8*, i8** %5
%20 = getelementptr inbounds i8, i8* %19, i64 3
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = add nsw i32 %18, %22
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = load i32, i32* %7
%26 = icmp ne i32 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %13
store i32 -1, i32* %4
br label %29
28: ; preds = %13
store i32 0, i32* %4
br label %29
29: ; preds = %28, %27
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@.str = [19 x i8] c"Wrong ACK received\00"
define i32 @handle_ack(i8* nocapture %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 4
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = tail call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = getelementptr inbounds i8, i8* %0, i64 2
%9 = load i8, i8* %8
%10 = zext i8 %9 to i32
%11 = shl nuw nsw i32 %10, 8
%12 = getelementptr inbounds i8, i8* %0, i64 3
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = or i32 %11, %14
%16 = icmp ne i32 %15, %2
%17 = sext i1 %16 to i32
ret i32 %17
}