#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__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *get_hex_digit_from_bin(char *binstr) {
  char *ret = (char *)malloc(3);
  int num = 0;
  num = (binstr[0] - 48) * 8 + (binstr[1] - 48) * 4 + (binstr[2] - 48) * 2 +
        (binstr[3] - 48) * 1;
  sprintf(ret, "%01x", num);
  return ret;
}


x86 assembly (clang, -O0):
<get_hex_digit_from_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x3,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
shl    $0x3,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x1(%rcx),%ecx
sub    $0x30,%ecx
shl    $0x2,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x2(%rcx),%ecx
sub    $0x30,%ecx
shl    $0x1,%ecx
add    %ecx,%eax
mov    -0x8(%rbp),%rcx
movsbl 0x3(%rcx),%ecx
sub    $0x30,%ecx
shl    $0x0,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe71(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hex_digit_from_bin>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x3,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
movsbl (%rbx),%eax
movsbl 0x1(%rbx),%ecx
shl    $0x2,%ecx
movsbl 0x2(%rbx),%edx
movsbl 0x3(%rbx),%esi
lea    (%rcx,%rax,8),%eax
lea    (%rax,%rdx,2),%eax
lea    (%rsi,%rax,1),%edx
add    $0xfffffd30,%edx
lea    0xea4(%rip),%rsi
mov    %r14,%rdi
call   1040 <sprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%01x\00"
define i8* @get_hex_digit_from_bin(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i64 @malloc(i32 3)
%6 = inttoptr i64 %5 to i8*
store i8* %6, i8** %3
store i32 0, i32* %4
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = sub nsw i32 %10, 48
%12 = mul nsw i32 %11, 8
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = sub nsw i32 %16, 48
%18 = mul nsw i32 %17, 4
%19 = add nsw i32 %12, %18
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i64 2
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = sub nsw i32 %23, 48
%25 = mul nsw i32 %24, 2
%26 = add nsw i32 %19, %25
%27 = load i8*, i8** %2
%28 = getelementptr inbounds i8, i8* %27, i64 3
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = sub nsw i32 %30, 48
%32 = mul nsw i32 %31, 1
%33 = add nsw i32 %26, %32
store i32 %33, i32* %4
%34 = load i8*, i8** %3
%35 = load i32, i32* %4
%36 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %35)
%37 = load i8*, i8** %3
ret i8* %37
}

LLVM IR (-O2):
@.str = [5 x i8] c"%01x\00"
define i8* @get_hex_digit_from_bin(i8* nocapture %0) {
%2 = tail call i64 @malloc(i32 3)
%3 = inttoptr i64 %2 to i8*
%4 = load i8, i8* %0
%5 = sext i8 %4 to i32
%6 = shl nsw i32 %5, 3
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = shl nsw i32 %9, 2
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = shl nsw i32 %13, 1
%15 = getelementptr inbounds i8, i8* %0, i64 3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = add nsw i32 %6, -720
%19 = add nsw i32 %18, %10
%20 = add nsw i32 %19, %14
%21 = add nsw i32 %20, %17
%22 = tail call i32 @sprintf(i8* dereferenceable(1) %3, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %21)
ret i8* %3
}