#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__ chk_calloc(int, int);
char *charToHex(char c) {
  char *res = (char *)chk_calloc(8, sizeof(char));
  int i;
  for (i = 0; i < 8; i++) {
    res[8 - 1 - i] = (c >> i) & 0x01;
  }
  return res;
}


x86 assembly (clang, -O0):
<charToHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x8,%edi
mov    $0x1,%esi
call   1030 <chk_calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
jge    1170 <charToHex+0x60>
movsbl -0x1(%rbp),%eax
mov    -0x14(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    $0x7,%ecx
sub    -0x14(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1138 <charToHex+0x28>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<charToHex>:
push   %rbx
mov    %edi,%ebx
mov    $0x8,%edi
mov    $0x1,%esi
call   1030 <chk_calloc@plt>
mov    %ebx,%ecx
and    $0x1,%cl
mov    %cl,0x7(%rax)
mov    %ebx,%ecx
shr    %cl
and    $0x1,%cl
mov    %cl,0x6(%rax)
mov    %ebx,%ecx
shr    $0x2,%cl
and    $0x1,%cl
mov    %cl,0x5(%rax)
mov    %ebx,%ecx
shr    $0x3,%cl
and    $0x1,%cl
mov    %cl,0x4(%rax)
mov    %ebx,%ecx
shr    $0x4,%cl
and    $0x1,%cl
mov    %cl,0x3(%rax)
mov    %ebx,%ecx
shr    $0x5,%cl
and    $0x1,%cl
mov    %cl,0x2(%rax)
mov    %ebx,%ecx
shr    $0x6,%cl
and    $0x1,%cl
mov    %cl,0x1(%rax)
shr    $0x7,%bl
mov    %bl,(%rax)
pop    %rbx
ret

LLVM IR (-O0):
define i8* @charToHex(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8*
%4 = alloca i32
store i8 %0, i8* %2
%5 = call i64 @chk_calloc(i32 8, i32 1)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %3
store i32 0, i32* %4
br label %7
7: ; preds = %22, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 8
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i8, i8* %2
%12 = sext i8 %11 to i32
%13 = load i32, i32* %4
%14 = ashr i32 %12, %13
%15 = and i32 %14, 1
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = sub nsw i32 7, %18
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 %16, i8* %21
br label %22
22: ; preds = %10
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %7
25: ; preds = %7
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
define i8* @charToHex(i8 signext %0) {
%2 = tail call i64 @chk_calloc(i32 8, i32 1)
%3 = inttoptr i64 %2 to i8*
%4 = and i8 %0, 1
%5 = getelementptr inbounds i8, i8* %3, i64 7
store i8 %4, i8* %5
%6 = lshr i8 %0, 1
%7 = and i8 %6, 1
%8 = getelementptr inbounds i8, i8* %3, i64 6
store i8 %7, i8* %8
%9 = lshr i8 %0, 2
%10 = and i8 %9, 1
%11 = getelementptr inbounds i8, i8* %3, i64 5
store i8 %10, i8* %11
%12 = lshr i8 %0, 3
%13 = and i8 %12, 1
%14 = getelementptr inbounds i8, i8* %3, i64 4
store i8 %13, i8* %14
%15 = lshr i8 %0, 4
%16 = and i8 %15, 1
%17 = getelementptr inbounds i8, i8* %3, i64 3
store i8 %16, i8* %17
%18 = lshr i8 %0, 5
%19 = and i8 %18, 1
%20 = getelementptr inbounds i8, i8* %3, i64 2
store i8 %19, i8* %20
%21 = lshr i8 %0, 6
%22 = and i8 %21, 1
%23 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %22, i8* %23
%24 = lshr i8 %0, 7
store i8 %24, i8* %3
ret i8* %3
}