#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 check_code(char *, int);
int /*<<< orphan*/ dump_hex(char *, int);
int /*<<< orphan*/ printf(char *, ...);
void dump_buffer(char *buffer) {
  dump_hex(buffer, 17);
  char code = check_code(buffer, 17 - 1) & 0xff;
  char current = buffer[17 - 1] & 0xff;
  if (current != code) {
    printf(" valid check code: %02x\n", code);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<dump_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x11,%esi
call   1040 <dump_hex@plt>
mov    -0x8(%rbp),%rdi
mov    $0x10,%esi
call   1050 <check_code@plt>
and    $0xff,%eax
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x10(%rax),%eax
and    $0xff,%eax
mov    %al,-0xa(%rbp)
movsbl -0xa(%rbp),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
je     1192 <dump_buffer+0x62>
movsbl -0x9(%rbp),%esi
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_buffer>:
push   %rbx
mov    %rdi,%rbx
mov    $0x11,%esi
call   1050 <dump_hex@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
call   1060 <check_code@plt>
movsbl 0x10(%rbx),%ecx
movsbl %al,%esi
cmp    %ecx,%esi
je     1174 <dump_buffer+0x34>
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [25 x i8] c" valid check code: %02x\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @dump_buffer(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @dump_hex(i8* %5, i32 17)
%7 = load i8*, i8** %2
%8 = call i32 @check_code(i8* %7, i32 16)
%9 = and i32 %8, 255
%10 = trunc i32 %9 to i8
store i8 %10, i8* %3
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 16
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = and i32 %14, 255
%16 = trunc i32 %15 to i8
store i8 %16, i8* %4
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = load i8, i8* %3
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %18, %20
br i1 %21, label %22, label %26
22: ; preds = %1
%23 = load i8, i8* %3
%24 = sext i8 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22, %1
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c" valid check code: %02x\0A\00"
define void @dump_buffer(i8* %0) {
%2 = tail call i32 @dump_hex(i8* %0, i32 17)
%3 = tail call i32 @check_code(i8* %0, i32 16)
%4 = getelementptr inbounds i8, i8* %0, i64 16
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = shl i32 %3, 24
%8 = ashr exact i32 %7, 24
%9 = icmp eq i32 %8, %6
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %12
12: ; preds = %10, %1
%13 = tail call i32 @putchar(i32 10)
ret void
}