#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 */
typedef int uint8_t;
typedef size_t uint16_t;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
scalar_t__ validate_crc(int *, size_t);
void on_message(uint8_t *msg, uint16_t len) {
  if (validate_crc(msg, len)) {
    for (uint16_t i = 0; i < len; i++) {
      printf("%02x", msg[i]);
    }
    printf("\n");
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<on_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <validate_crc@plt>
cmp    $0x0,%rax
je     11b3 <on_message+0x83>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1197 <on_message+0x67>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115f <on_message+0x2f>
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<on_message>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
call   1040 <validate_crc@plt>
test   %rax,%rax
je     11aa <on_message+0x6a>
test   %r12,%r12
je     1187 <on_message+0x47>
lea    0xe9c(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1170 <on_message+0x30>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <fflush@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c"\0A\00"
@stdout = global i32 0
define void @on_message(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%6 = load i32*, i32** %3
%7 = load i64, i64* %4
%8 = call i64 @validate_crc(i32* %6, i64 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %28
10: ; preds = %2
store i64 0, i64* %5
br label %11
11: ; preds = %21, %10
%12 = load i64, i64* %5
%13 = load i64, i64* %4
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load i32*, i32** %3
%17 = load i64, i64* %5
%18 = getelementptr inbounds i32, i32* %16, i64 %17
%19 = load i32, i32* %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %15
%22 = load i64, i64* %5
%23 = add i64 %22, 1
store i64 %23, i64* %5
br label %11
24: ; preds = %11
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
br label %28
28: ; preds = %24, %2
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
@stdout = global i32 0
define void @on_message(i32* %0, i64 %1) {
%3 = tail call i64 @validate_crc(i32* %0, i64 %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = icmp eq i64 %1, 0
br i1 %6, label %7, label %11
7: ; preds = %11, %5
%8 = tail call i32 @putchar(i32 10)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
br label %18
11: ; preds = %5, %11
%12 = phi i64 [ %16, %11 ], [ 0, %5 ]
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = add nuw i64 %12, 1
%17 = icmp eq i64 %16, %1
br i1 %17, label %7, label %11
18: ; preds = %7, %2
ret void
}