#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*/ printf(char *, char const, ...);
void onReceiveHandler(const char *ip, const char *buffer, int len) {
  int i;
  printf("Received %d bytes from %s:\n", len, ip);
  for (i = 0; i < len - 1; ++i) {
    printf("0x%02X ", buffer[i]);
  }
  printf("0x%02X\n", buffer[len - 1]);
}


x86 assembly (clang, -O0):
<onReceiveHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x8(%rbp),%rdx
lea    0xecf(%rip),%rdi
movsbl %al,%esi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    117b <onReceiveHandler+0x6b>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xeba(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1142 <onReceiveHandler+0x32>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
lea    0xe95(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<onReceiveHandler>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r12
mov    %rdi,%rdx
movsbl %r14b,%esi
lea    0xed4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    -0x1(%r14),%r15d
cmp    $0x2,%r14d
jl     1168 <onReceiveHandler+0x58>
mov    %r15d,%ebp
lea    0xed5(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r12,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <onReceiveHandler+0x40>
movslq %r15d,%rax
movsbl (%r12,%rax,1),%esi
lea    0xead(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Received %d bytes from %s:\0A\00"
@.str.1 = [8 x i8] c"0x%02X \00"
@.str.2 = [8 x i8] c"0x%02X\0A\00"
define void @onReceiveHandler(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = trunc i32 %8 to i8
%10 = load i8*, i8** %4
%11 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8 signext %9, i8* %10)
store i32 0, i32* %7
br label %12
12: ; preds = %24, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %6
%15 = sub nsw i32 %14, 1
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %27
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8 signext %22)
br label %24
24: ; preds = %17
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %12
27: ; preds = %12
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
%33 = load i8, i8* %32
%34 = call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext %33)
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"Received %d bytes from %s:\0A\00"
@.str.1 = [8 x i8] c"0x%02X \00"
@.str.2 = [8 x i8] c"0x%02X\0A\00"
define void @onReceiveHandler(i8* %0, i8* nocapture %1, i32 %2) {
%4 = trunc i32 %2 to i8
%5 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8 signext %4, i8* %0)
%6 = add i32 %2, -1
%7 = icmp sgt i32 %2, 1
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = zext i32 %6 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8 signext %13)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %9
br i1 %16, label %17, label %10
17: ; preds = %10, %3
%18 = sext i32 %6 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = tail call i32 (i8*, i8, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8 signext %20)
ret void
}