#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 */
char hexdigit(char const);
int /*<<< orphan*/ write(int, char *, int);
void hexdump(int fd, const void *buffer, size_t count) {
  const char *p = (const char *)buffer;
  char outbuf[2];
  while (count--) {
    outbuf[0] = hexdigit(((*p) & 0xf0) >> 4);
    outbuf[1] = hexdigit((*p) & 0x0f);
    write(fd, outbuf, 2);
    p++;
  }
}


x86 assembly (clang, -O0):
<hexdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
je     11a5 <hexdump+0x85>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
and    $0xf0,%eax
sar    $0x4,%eax
movsbl %al,%edi
call   1040 <hexdigit@plt>
mov    %al,-0x22(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
and    $0xf,%eax
movsbl %al,%edi
call   1040 <hexdigit@plt>
mov    %al,-0x21(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113b <hexdump+0x1b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hexdump>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdx,%rdx
je     118c <hexdump+0x6c>
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%r12d
xor    %ebp,%ebp
lea    0xe(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%eax
shr    $0x4,%al
movzbl %al,%edi
call   1040 <hexdigit@plt>
mov    %al,0xe(%rsp)
movzbl (%rbx,%rbp,1),%edi
and    $0xf,%edi
call   1040 <hexdigit@plt>
mov    %al,0xf(%rsp)
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x2,%edx
call   1030 <write@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1150 <hexdump+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @hexdump(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca [2 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %5
store i8* %9, i8** %7
br label %10
10: ; preds = %14, %3
%11 = load i64, i64* %6
%12 = add i64 %11, -1
store i64 %12, i64* %6
%13 = icmp ne i64 %11, 0
br i1 %13, label %14, label %35
14: ; preds = %10
%15 = load i8*, i8** %7
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = and i32 %17, 240
%19 = ashr i32 %18, 4
%20 = trunc i32 %19 to i8
%21 = call signext i8 @hexdigit(i8 signext %20)
%22 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
store i8 %21, i8* %22
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = and i32 %25, 15
%27 = trunc i32 %26 to i8
%28 = call signext i8 @hexdigit(i8 signext %27)
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 1
store i8 %28, i8* %29
%30 = load i32, i32* %4
%31 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%32 = call i32 @write(i32 %30, i8* %31, i32 2)
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %7
br label %10
35: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @hexdump(i32 %0, i8* nocapture %1, i64 %2) {
%4 = alloca [2 x i8]
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 0
%6 = icmp eq i64 %2, 0
br i1 %6, label %22, label %7
7: ; preds = %3
%8 = getelementptr inbounds [2 x i8], [2 x i8]* %4, i64 0, i64 1
br label %9
9: ; preds = %7, %9
%10 = phi i8* [ %1, %7 ], [ %20, %9 ]
%11 = phi i64 [ %2, %7 ], [ %12, %9 ]
%12 = add i64 %11, -1
%13 = load i8, i8* %10
%14 = lshr i8 %13, 4
%15 = tail call signext i8 @hexdigit(i8 signext %14)
store i8 %15, i8* %5
%16 = load i8, i8* %10
%17 = and i8 %16, 15
%18 = tail call signext i8 @hexdigit(i8 signext %17)
store i8 %18, i8* %8
%19 = call i32 @write(i32 %0, i8* %5, i32 2)
%20 = getelementptr inbounds i8, i8* %10, i64 1
%21 = icmp eq i64 %12, 0
br i1 %21, label %22, label %9
22: ; preds = %9, %3
ret void
}