#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 *malloc(int);
char *hex_representation(const unsigned char *bytes, size_t size) {
  static const char *hex_digits = "0123456789abcdef";
  char *str = malloc(2 * size + 1);
  size_t i;
  if (!str) {
    return NULL;
  }
  for (i = 0; i < size; i++) {
    str[2 * i] = hex_digits[bytes[i] >> 4];
    str[2 * i + 1] = hex_digits[bytes[i] & 0x0f];
  }
  str[2 * size] = '\0';
  return str;
}


x86 assembly (clang, -O0):
<hex_representation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    114f <hex_representation+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <hex_representation+0xd5>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11cd <hex_representation+0xbd>
mov    0x2ebc(%rip),%rax
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
sar    $0x4,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,(%rax,%rcx,1)
mov    0x2e91(%rip),%rax
mov    -0x10(%rbp),%rcx
mov    -0x28(%rbp),%rdx
movzbl (%rcx,%rdx,1),%ecx
and    $0xf,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
shl    $0x1,%rcx
mov    %dl,0x1(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1157 <hex_representation+0x47>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_representation>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
mov    %rdi,%r14
lea    (%rsi,%rsi,1),%r15
lea    0x1(%r15),%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     116c <hex_representation+0x5c>
test   %r12,%r12
je     1167 <hex_representation+0x57>
xor    %ecx,%ecx
lea    0xec2(%rip),%rdx
xchg   %ax,%ax
movzbl (%r14,%rcx,1),%esi
mov    %rsi,%rdi
shr    $0x4,%rdi
movzbl (%rdi,%rdx,1),%ebx
mov    %bl,(%rax,%rcx,2)
and    $0xf,%esi
movzbl (%rsi,%rdx,1),%ebx
mov    %bl,0x1(%rax,%rcx,2)
add    $0x1,%rcx
cmp    %rcx,%r12
jne    1140 <hex_representation+0x30>
movb   $0x0,(%rax,%r15,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
define noalias i8* @hex_representation(i8* nocapture %0, i64 %1) {
%3 = shl i64 %1, 1
%4 = trunc i64 %3 to i32
%5 = or i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %30, label %8
8: ; preds = %2
%9 = icmp eq i64 %1, 0
br i1 %9, label %28, label %10
10: ; preds = %8, %10
%11 = phi i64 [ %26, %10 ], [ 0, %8 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = lshr i8 %13, 4
%15 = zext i8 %14 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = shl i64 %11, 1
%19 = getelementptr inbounds i8, i8* %6, i64 %18
store i8 %17, i8* %19
%20 = and i8 %13, 15
%21 = zext i8 %20 to i64
%22 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = or i64 %18, 1
%25 = getelementptr inbounds i8, i8* %6, i64 %24
store i8 %23, i8* %25
%26 = add nuw i64 %11, 1
%27 = icmp eq i64 %26, %1
br i1 %27, label %28, label %10
28: ; preds = %10, %8
%29 = getelementptr inbounds i8, i8* %6, i64 %3
store i8 0, i8* %29
br label %30
30: ; preds = %2, %28
ret i8* %6
}