#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*/ snprintf(char *, int, char *, unsigned char, ...);
char *xmalloc(int);
char *join_to_fourhex(unsigned char hex0, unsigned char hex1) {
  char *tmp;
  tmp = xmalloc(5);
  if (hex0 != 0) {
    snprintf(tmp, 4, "%x%2x", hex0, hex1);
  } else {
    snprintf(tmp, 4, "%x", hex1);
  }
  return tmp;
}


x86 assembly (clang, -O0):
<join_to_fourhex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %sil,%al
mov    %dil,%cl
mov    %cl,-0x1(%rbp)
mov    %al,-0x2(%rbp)
mov    $0x5,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x10(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x0,%eax
je     1176 <join_to_fourhex+0x56>
mov    -0x10(%rbp),%rdi
mov    -0x1(%rbp),%al
movzbl -0x2(%rbp),%r8d
mov    $0x4,%esi
lea    0xe99(%rip),%rdx
movzbl %al,%ecx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    1191 <join_to_fourhex+0x71>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
lea    0xe80(%rip),%rdx
movzbl -0x2(%rbp),%ecx
mov    $0x0,%al
call   1030 <snprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_to_fourhex>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %edi,%ebx
mov    $0x5,%edi
call   1040 <xmalloc@plt>
mov    %rax,%r14
test   %ebx,%ebx
je     1158 <join_to_fourhex+0x38>
movzbl %bpl,%r8d
movzbl %bl,%ecx
lea    0xeb9(%rip),%rdx
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    1172 <join_to_fourhex+0x52>
movzbl %bpl,%ecx
lea    0xea3(%rip),%rdx
mov    %r14,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%x%2x\00"
@.str.1 = [3 x i8] c"%x\00"
define i8* @join_to_fourhex(i8 zeroext %0, i8 zeroext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8*
store i8 %0, i8* %3
store i8 %1, i8* %4
%6 = call i8* @xmalloc(i32 5)
store i8* %6, i8** %5
%7 = load i8, i8* %3
%8 = zext i8 %7 to i32
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8*, i8** %5
%12 = load i8, i8* %3
%13 = load i8, i8* %4
%14 = zext i8 %13 to i32
%15 = call i32 (i8*, i32, i8*, i8, ...) @snprintf(i8* %11, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %12, i32 %14)
br label %20
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = load i8, i8* %4
%19 = call i32 (i8*, i32, i8*, i8, ...) @snprintf(i8* %17, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %18)
br label %20
20: ; preds = %16, %10
%21 = load i8*, i8** %5
ret i8* %21
}

LLVM IR (-O2):
@.str = [6 x i8] c"%x%2x\00"
@.str.1 = [3 x i8] c"%x\00"
define i8* @join_to_fourhex(i8 zeroext %0, i8 zeroext %1) {
%3 = tail call i8* @xmalloc(i32 5)
%4 = icmp eq i8 %0, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = zext i8 %1 to i32
%7 = tail call i32 (i8*, i32, i8*, i8, ...) @snprintf(i8* %3, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %0, i32 %6)
br label %10
8: ; preds = %2
%9 = tail call i32 (i8*, i32, i8*, i8, ...) @snprintf(i8* %3, i32 4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %1)
br label %10
10: ; preds = %8, %5
ret i8* %3
}