#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 */
scalar_t__ isprint(char);
int /*<<< orphan*/ printf(char *, ...);
char dump_byte(char b) {
  b > 0 ? printf("%02x", b) : printf("00");
  return (isprint(b) ? b : '.');
}


x86 assembly (clang, -O0):
<dump_byte>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
cmp    $0x0,%eax
jle    1152 <dump_byte+0x32>
movsbl -0x1(%rbp),%esi
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1160 <dump_byte+0x40>
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x1(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     117f <dump_byte+0x5f>
movsbl -0x1(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    118c <dump_byte+0x6c>
mov    $0x2e,%eax
mov    %eax,-0x8(%rbp)
jmp    118c <dump_byte+0x6c>
mov    -0x8(%rbp),%eax
movsbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_byte>:
push   %rbx
movzbl %dil,%ebx
test   %dil,%dil
jle    113c <dump_byte+0x1c>
lea    0xecf(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    114a <dump_byte+0x2a>
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movsbl %bl,%edi
call   1040 <isprint@plt>
test   %rax,%rax
mov    $0x2e,%eax
cmovne %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
@.str.1 = [3 x i8] c"00\00"
define signext i8 @dump_byte(i8 signext %0) {
%2 = alloca i8
store i8 %0, i8* %2
%3 = load i8, i8* %2
%4 = sext i8 %3 to i32
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %12
10: ; preds = %1
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = phi i32 [ %9, %6 ], [ %11, %10 ]
%14 = load i8, i8* %2
%15 = call i64 @isprint(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
br label %21
20: ; preds = %12
br label %21
21: ; preds = %20, %17
%22 = phi i32 [ %19, %17 ], [ 46, %20 ]
%23 = trunc i32 %22 to i8
ret i8 %23
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
@.str.1 = [3 x i8] c"00\00"
define signext i8 @dump_byte(i8 signext %0) {
%2 = icmp sgt i8 %0, 0
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = zext i8 %0 to i32
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %8
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = tail call i64 @isprint(i8 signext %0)
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, i8 46, i8 %0
ret i8 %11
}