#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 /*<<< orphan*/ sprintf(char *, char *, ...);
const char *data_to_hex(const unsigned char *a, size_t n) {
  static char buf[100];
  if (!a) {
    sprintf(buf, "NULL");
  } else if (n < 33) {
    char *p = buf;
    size_t i;
    for (i = 0; i < n; ++i) {
      p += sprintf(p, "%02X ", a[i]);
    }
    if (p != buf) {
      *--p = '\0';
    }
  } else {
    sprintf(buf, "data[%zu] too long", n);
  }
  return buf;
}


x86 assembly (clang, -O0):
<data_to_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1145 <data_to_hex+0x35>
lea    0x2f0e(%rip),%rdi
lea    0xec7(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11f7 <data_to_hex+0xe7>
cmpq   $0x21,-0x10(%rbp)
jae    11d9 <data_to_hex+0xc9>
lea    0x2ee9(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b0 <data_to_hex+0xa0>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1163 <data_to_hex+0x53>
lea    0x2e89(%rip),%rax
cmp    %rax,-0x18(%rbp)
je     11d4 <data_to_hex+0xc4>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,-0x1(%rax)
jmp    11f2 <data_to_hex+0xe2>
mov    -0x10(%rbp),%rdx
lea    0x2e5c(%rip),%rdi
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11f7 <data_to_hex+0xe7>
lea    0x2e42(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_to_hex>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     1175 <data_to_hex+0x65>
mov    %rsi,%r14
cmp    $0x20,%rsi
ja     1188 <data_to_hex+0x78>
test   %r14,%r14
je     11a0 <data_to_hex+0x90>
mov    %rdi,%r12
lea    0x2f0a(%rip),%rax
lea    0xec8(%rip),%r15
xor    %ebx,%ebx
nop
mov    %rax,%r13
movzbl (%r12,%rbx,1),%edx
mov    %rax,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <sprintf@plt>
cltq
add    %r13,%rax
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1140 <data_to_hex+0x30>
lea    0x2ed6(%rip),%rcx
cmp    %rcx,%rax
je     11a0 <data_to_hex+0x90>
movb   $0x0,-0x1(%rax)
jmp    11a0 <data_to_hex+0x90>
movb   $0x0,0x2ec8(%rip)
movl   $0x4c4c554e,0x2eba(%rip)
55 4c 4c
jmp    11a0 <data_to_hex+0x90>
lea    0x2eb1(%rip),%rdi
lea    0xe75(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <sprintf@plt>
lea    0x2e99(%rip),%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@data_to_hex.buf = internal global [100 x i8] zeroinitializer
@.str = [5 x i8] c"NULL\00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [19 x i8] c"data[%zu] too long\00"
define i8* @data_to_hex(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @data_to_hex.buf, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %44
11: ; preds = %2
%12 = load i64, i64* %4
%13 = icmp ult i64 %12, 33
br i1 %13, label %14, label %40
14: ; preds = %11
store i8* getelementptr inbounds ([100 x i8], [100 x i8]* @data_to_hex.buf, i64 0, i64 0), i8** %5
store i64 0, i64* %6
br label %15
15: ; preds = %30, %14
%16 = load i64, i64* %6
%17 = load i64, i64* %4
%18 = icmp ult i64 %16, %17
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = load i8*, i8** %3
%22 = load i64, i64* %6
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i8*, i8** %5
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %27, i64 %28
store i8* %29, i8** %5
br label %30
30: ; preds = %19
%31 = load i64, i64* %6
%32 = add i64 %31, 1
store i64 %32, i64* %6
br label %15
33: ; preds = %15
%34 = load i8*, i8** %5
%35 = icmp ne i8* %34, getelementptr inbounds ([100 x i8], [100 x i8]* @data_to_hex.buf, i64 0, i64 0)
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i32 -1
store i8* %38, i8** %5
store i8 0, i8* %38
br label %39
39: ; preds = %36, %33
br label %43
40: ; preds = %11
%41 = load i64, i64* %4
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @data_to_hex.buf, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 %41)
br label %43
43: ; preds = %40, %39
br label %44
44: ; preds = %43, %9
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @data_to_hex.buf, i64 0, i64 0)
}

LLVM IR (-O2):
@data_to_hex.buf = internal global [100 x i8] zeroinitializer
@.str = [5 x i8] c"NULL\00"
@.str.1 = [6 x i8] c"%02X \00"
@.str.2 = [19 x i8] c"data[%zu] too long\00"
define i8* @data_to_hex(i8* %0, i64 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %5
4: ; preds = %2
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 16 dereferenceable(5) getelementptr inbounds ([100 x i8], [100 x i8]* @data_to_hex.buf, i64 0, i64 0), i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5, i1 false)
br label %26
5: ; preds = %2
%6 = icmp ult i64 %1, 33
br i1 %6, label %7, label %24
7: ; preds = %5
%8 = icmp eq i64 %1, 0
br i1 %8, label %26, label %9
9: ; preds = %7, %9
%10 = phi i64 [ %18, %9 ], [ 0, %7 ]
%11 = phi i8* [ %17, %9 ], [ getelementptr inbounds ([100 x i8], [100 x i8]* @data_to_hex.buf, i64 0, i64 0), %7 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %11, i64 %16
%18 = add nuw i64 %10, 1
%19 = icmp eq i64 %18, %1
br i1 %19, label %20, label %9
20: ; preds = %9
%21 = icmp eq i8* %17, getelementptr inbounds ([100 x i8], [100 x i8]* @data_to_hex.buf, i64 0, i64 0)
br i1 %21, label %26, label %22
22: ; preds = %20
%23 = getelementptr inbounds i8, i8* %17, i64 -1
store i8 0, i8* %23
br label %26
24: ; preds = %5
%25 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) getelementptr inbounds ([100 x i8], [100 x i8]* @data_to_hex.buf, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i64 %1)
br label %26
26: ; preds = %7, %20, %22, %24, %4
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @data_to_hex.buf, i64 0, i64 0)
}