#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 */
const char *gpsd_hexdump(char *binbuf, size_t binbuflen) {
  static char hexbuf[516 * 2 + 1];
  size_t i, j = 0;
  size_t len = (size_t)((binbuflen > 516) ? 516 : binbuflen);
  const char *ibuf = (const char *)binbuf;
  const char *hexchar = "0123456789abcdef";
  if (NULL == binbuf || 0 == binbuflen)
    return "";
  for (i = 0; i < len; i++) {
    hexbuf[j++] = hexchar[(ibuf[i] & 0xf0) >> 4];
    hexbuf[j++] = hexchar[ibuf[i] & 0x0f];
  }
  hexbuf[j] = '\0';
  return hexbuf;
}


x86 assembly (clang, -O0):
<gpsd_hexdump>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x204,-0x18(%rbp)
jbe    1130 <gpsd_hexdump+0x30>
mov    $0x204,%eax
mov    %rax,-0x48(%rbp)
jmp    1138 <gpsd_hexdump+0x38>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xeb1(%rip),%rax
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     116b <gpsd_hexdump+0x6b>
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    117b <gpsd_hexdump+0x7b>
lea    0xe9e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1226 <gpsd_hexdump+0x126>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    120c <gpsd_hexdump+0x10c>
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
and    $0xf0,%ecx
sar    $0x4,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
lea    0x2e6a(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
and    $0xf,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x28(%rbp),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
lea    0x2e38(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1183 <gpsd_hexdump+0x83>
mov    -0x28(%rbp),%rcx
lea    0x2e19(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2e0e(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<gpsd_hexdump>:
cmp    $0x204,%rsi
mov    $0x204,%ecx
cmovb  %rsi,%rcx
lea    0xef9(%rip),%rax
test   %rdi,%rdi
je     117a <gpsd_hexdump+0x7a>
test   %rsi,%rsi
je     117a <gpsd_hexdump+0x7a>
test   %rcx,%rcx
je     116d <gpsd_hexdump+0x6d>
add    %rcx,%rcx
xor    %edx,%edx
lea    0xece(%rip),%r8
lea    0x2ef7(%rip),%rsi
nopl   0x0(%rax)
movzbl (%rdi),%eax
shr    $0x4,%rax
movzbl (%rax,%r8,1),%eax
mov    %al,(%rdx,%rsi,1)
movzbl (%rdi),%eax
and    $0xf,%eax
movzbl (%rax,%r8,1),%eax
mov    %al,0x1(%rdx,%rsi,1)
add    $0x2,%rdx
add    $0x1,%rdi
cmp    %rdx,%rcx
jne    1140 <gpsd_hexdump+0x40>
jmp    116f <gpsd_hexdump+0x6f>
xor    %edx,%edx
lea    0x2eba(%rip),%rax
movb   $0x0,(%rdx,%rax,1)
ret

LLVM IR (-O0):
@gpsd_hexdump.hexbuf = internal global [1033 x i8] zeroinitializer
@.str = [17 x i8] c"0123456789abcdef\00"
@.str.1 = [1 x i8] zeroinitializer
define i8* @gpsd_hexdump(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 0, i64* %7
%11 = load i64, i64* %5
%12 = icmp ugt i64 %11, 516
br i1 %12, label %13, label %14
13: ; preds = %2
br label %16
14: ; preds = %2
%15 = load i64, i64* %5
br label %16
16: ; preds = %14, %13
%17 = phi i64 [ 516, %13 ], [ %15, %14 ]
store i64 %17, i64* %8
%18 = load i8*, i8** %4
store i8* %18, i8** %9
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %10
%19 = load i8*, i8** %4
%20 = icmp eq i8* null, %19
br i1 %20, label %24, label %21
21: ; preds = %16
%22 = load i64, i64* %5
%23 = icmp eq i64 0, %22
br i1 %23, label %24, label %25
24: ; preds = %21, %16
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %64
25: ; preds = %21
store i64 0, i64* %6
br label %26
26: ; preds = %58, %25
%27 = load i64, i64* %6
%28 = load i64, i64* %8
%29 = icmp ult i64 %27, %28
br i1 %29, label %30, label %61
30: ; preds = %26
%31 = load i8*, i8** %10
%32 = load i8*, i8** %9
%33 = load i64, i64* %6
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = and i32 %36, 240
%38 = ashr i32 %37, 4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %31, i64 %39
%41 = load i8, i8* %40
%42 = load i64, i64* %7
%43 = add i64 %42, 1
store i64 %43, i64* %7
%44 = getelementptr inbounds [1033 x i8], [1033 x i8]* @gpsd_hexdump.hexbuf, i64 0, i64 %42
store i8 %41, i8* %44
%45 = load i8*, i8** %10
%46 = load i8*, i8** %9
%47 = load i64, i64* %6
%48 = getelementptr inbounds i8, i8* %46, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = and i32 %50, 15
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %45, i64 %52
%54 = load i8, i8* %53
%55 = load i64, i64* %7
%56 = add i64 %55, 1
store i64 %56, i64* %7
%57 = getelementptr inbounds [1033 x i8], [1033 x i8]* @gpsd_hexdump.hexbuf, i64 0, i64 %55
store i8 %54, i8* %57
br label %58
58: ; preds = %30
%59 = load i64, i64* %6
%60 = add i64 %59, 1
store i64 %60, i64* %6
br label %26
61: ; preds = %26
%62 = load i64, i64* %7
%63 = getelementptr inbounds [1033 x i8], [1033 x i8]* @gpsd_hexdump.hexbuf, i64 0, i64 %62
store i8 0, i8* %63
store i8* getelementptr inbounds ([1033 x i8], [1033 x i8]* @gpsd_hexdump.hexbuf, i64 0, i64 0), i8** %3
br label %64
64: ; preds = %61, %24
%65 = load i8*, i8** %3
ret i8* %65
}

LLVM IR (-O2):
@gpsd_hexdump.hexbuf = internal global [1033 x i8] zeroinitializer
@.str = [17 x i8] c"0123456789abcdef\00"
@.str.1 = [1 x i8] zeroinitializer
define i8* @gpsd_hexdump(i8* %0, i64 %1) {
%3 = icmp ult i64 %1, 516
%4 = select i1 %3, i64 %1, i64 516
%5 = icmp eq i8* %0, null
%6 = icmp eq i64 %1, 0
%7 = or i1 %5, %6
br i1 %7, label %33, label %8
8: ; preds = %2
%9 = icmp eq i64 %4, 0
br i1 %9, label %30, label %10
10: ; preds = %8, %10
%11 = phi i64 [ %28, %10 ], [ 0, %8 ]
%12 = phi i64 [ %26, %10 ], [ 0, %8 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %11
%14 = load i8, i8* %13
%15 = lshr i8 %14, 4
%16 = zext i8 %15 to i64
%17 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = or i64 %12, 1
%20 = getelementptr inbounds [1033 x i8], [1033 x i8]* @gpsd_hexdump.hexbuf, i64 0, i64 %12
store i8 %18, i8* %20
%21 = load i8, i8* %13
%22 = and i8 %21, 15
%23 = zext i8 %22 to i64
%24 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = add nuw nsw i64 %12, 2
%27 = getelementptr inbounds [1033 x i8], [1033 x i8]* @gpsd_hexdump.hexbuf, i64 0, i64 %19
store i8 %25, i8* %27
%28 = add nuw nsw i64 %11, 1
%29 = icmp eq i64 %28, %4
br i1 %29, label %30, label %10
30: ; preds = %10, %8
%31 = phi i64 [ 0, %8 ], [ %26, %10 ]
%32 = getelementptr inbounds [1033 x i8], [1033 x i8]* @gpsd_hexdump.hexbuf, i64 0, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %2, %30
%34 = phi i8* [ getelementptr inbounds ([1033 x i8], [1033 x i8]* @gpsd_hexdump.hexbuf, i64 0, i64 0), %30 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %2 ]
ret i8* %34
}