#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*/ printf(char *, ...);
unsigned int strlen(char const *);
void print_hex(const char *const name, const char *val) {
  unsigned int hexlen;
  printf("   %-46s : constant         := 16#", name);
  for (hexlen = strlen(val); hexlen > 0;) {
    const unsigned int len = hexlen % 4 ?: 4;
    char quad[] = "0000";
    unsigned int i;
    for (i = 0; i < len; ++i)
      quad[4 - len + i] = val[i];
    printf("%s", quad);
    val += len;
    hexlen -= len;
    if (hexlen > 0)
      printf("_");
  }
  printf("#;\n");
}


x86 assembly (clang, -O0):
<print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jbe    1220 <print_hex+0x100>
mov    -0x14(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     1175 <print_hex+0x55>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1182 <print_hex+0x62>
mov    $0x4,%eax
mov    %eax,-0x2c(%rbp)
jmp    1182 <print_hex+0x62>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0xe95(%rip),%eax
mov    %eax,-0x1d(%rbp)
mov    0xe90(%rip),%al
mov    %al,-0x19(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    11d6 <print_hex+0xb6>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,1),%cl
mov    $0x4,%eax
sub    -0x18(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,%eax
mov    %cl,-0x1d(%rbp,%rax,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a1 <print_hex+0x81>
lea    -0x1d(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jbe    121b <print_hex+0xfb>
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    114e <print_hex+0x2e>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     1267 <print_hex+0x127>
mov    %eax,%r13d
lea    0xeaf(%rip),%r14
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r13d,%r12d
and    $0x3,%r12d
mov    $0x4,%eax
cmove  %eax,%r12d
movb   $0x0,0x4(%rsp)
movl   $0x30303030,(%rsp)
lea    -0x1(%r12),%rcx
mov    %r12d,%edi
and    $0x3,%edi
cmp    $0x3,%rcx
jae    11c0 <print_hex+0x80>
xor    %ecx,%ecx
jmp    121c <print_hex+0xdc>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x4,%edx
sub    %r12d,%edx
mov    %r12d,%esi
and    $0xfffffffc,%esi
add    $0xfffffffc,%edx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rbx,%rcx,1),%eax
lea    (%rdx,%rcx,1),%ebp
add    $0x4,%ebp
mov    %al,(%rsp,%rbp,1)
movzbl 0x1(%rbx,%rcx,1),%eax
lea    0x5(%rdx,%rcx,1),%ebp
mov    %al,(%rsp,%rbp,1)
movzbl 0x2(%rbx,%rcx,1),%eax
lea    0x6(%rdx,%rcx,1),%ebp
mov    %al,(%rsp,%rbp,1)
movzbl 0x3(%rbx,%rcx,1),%eax
lea    (%rdx,%rcx,1),%ebp
add    $0x7,%ebp
mov    %al,(%rsp,%rbp,1)
add    $0x4,%rcx
cmp    %rcx,%rsi
jne    11e0 <print_hex+0xa0>
test   %rdi,%rdi
je     1243 <print_hex+0x103>
lea    (%rbx,%rcx,1),%rdx
sub    %r12d,%ecx
add    $0x4,%ecx
xor    %esi,%esi
nopl   (%rax)
movzbl (%rdx,%rsi,1),%eax
lea    (%rcx,%rsi,1),%ebp
mov    %al,(%rsp,%rbp,1)
add    $0x1,%rsi
cmp    %rsi,%rdi
jne    1230 <print_hex+0xf0>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
sub    %r12d,%r13d
je     1267 <print_hex+0x127>
add    %r12,%rbx
mov    $0x5f,%edi
call   1030 <putchar@plt>
jmp    1180 <print_hex+0x40>
lea    0xdbd(%rip),%rdi
call   1040 <puts@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c" %-46s : constant := 16#\00"
@__const.print_hex.quad = [5 x i8] c"0000\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"_\00"
@.str.3 = [4 x i8] c"#;\0A\00"
define void @print_hex(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [5 x i8]
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %5
br label %13
13: ; preds = %58, %2
%14 = load i32, i32* %5
%15 = icmp ugt i32 %14, 0
br i1 %15, label %16, label %59
16: ; preds = %13
%17 = load i32, i32* %5
%18 = urem i32 %17, 4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
br label %22
21: ; preds = %16
br label %22
22: ; preds = %21, %20
%23 = phi i32 [ %18, %20 ], [ 4, %21 ]
store i32 %23, i32* %6
%24 = bitcast [5 x i8]* %7 to i8*
store i32 0, i32* %8
br label %25
25: ; preds = %41, %22
%26 = load i32, i32* %8
%27 = load i32, i32* %6
%28 = icmp ult i32 %26, %27
br i1 %28, label %29, label %44
29: ; preds = %25
%30 = load i8*, i8** %4
%31 = load i32, i32* %8
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = load i8, i8* %33
%35 = load i32, i32* %6
%36 = sub i32 4, %35
%37 = load i32, i32* %8
%38 = add i32 %36, %37
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 %39
store i8 %34, i8* %40
br label %41
41: ; preds = %29
%42 = load i32, i32* %8
%43 = add i32 %42, 1
store i32 %43, i32* %8
br label %25
44: ; preds = %25
%45 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = load i32, i32* %6
%48 = load i8*, i8** %4
%49 = zext i32 %47 to i64
%50 = getelementptr inbounds i8, i8* %48, i64 %49
store i8* %50, i8** %4
%51 = load i32, i32* %6
%52 = load i32, i32* %5
%53 = sub i32 %52, %51
store i32 %53, i32* %5
%54 = load i32, i32* %5
%55 = icmp ugt i32 %54, 0
br i1 %55, label %56, label %58
56: ; preds = %44
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %58
58: ; preds = %56, %44
br label %13
59: ; preds = %13
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c" %-46s : constant := 16#\00"
@__const.print_hex.quad = [5 x i8] c"0000\00"
@.str.1 = [3 x i8] c"%s\00"
@str = [3 x i8] c"#;\00"
define void @print_hex(i8* %0, i8* %1) {
%3 = alloca [5 x i8]
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %79, label %7
7: ; preds = %2
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
br label %9
9: ; preds = %74, %7
%10 = phi i8* [ %1, %7 ], [ %76, %74 ]
%11 = phi i32 [ %5, %7 ], [ %72, %74 ]
%12 = and i32 %11, 3
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i32 4, i32 %12
%15 = sub nuw nsw i32 4, %14
%16 = zext i32 %14 to i64
%17 = add nsw i64 %16, -1
%18 = and i64 %16, 3
%19 = icmp ult i64 %17, 3
br i1 %19, label %55, label %20
20: ; preds = %9
%21 = and i64 %16, 4
br label %22
22: ; preds = %22, %20
%23 = phi i64 [ 0, %20 ], [ %52, %22 ]
%24 = phi i64 [ 0, %20 ], [ %53, %22 ]
%25 = trunc i64 %23 to i32
%26 = getelementptr inbounds i8, i8* %10, i64 %23
%27 = load i8, i8* %26
%28 = add nsw i32 %15, %25
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 %29
store i8 %27, i8* %30
%31 = or i64 %23, 1
%32 = trunc i64 %31 to i32
%33 = getelementptr inbounds i8, i8* %10, i64 %31
%34 = load i8, i8* %33
%35 = add nsw i32 %15, %32
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 %36
store i8 %34, i8* %37
%38 = or i64 %23, 2
%39 = trunc i64 %38 to i32
%40 = getelementptr inbounds i8, i8* %10, i64 %38
%41 = load i8, i8* %40
%42 = add nsw i32 %15, %39
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 %43
store i8 %41, i8* %44
%45 = or i64 %23, 3
%46 = trunc i64 %45 to i32
%47 = getelementptr inbounds i8, i8* %10, i64 %45
%48 = load i8, i8* %47
%49 = add nsw i32 %15, %46
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 %50
store i8 %48, i8* %51
%52 = add nuw nsw i64 %23, 4
%53 = add i64 %24, 4
%54 = icmp eq i64 %53, %21
br i1 %54, label %55, label %22
55: ; preds = %22, %9
%56 = phi i64 [ 0, %9 ], [ %52, %22 ]
%57 = icmp eq i64 %18, 0
br i1 %57, label %70, label %58
58: ; preds = %55, %58
%59 = phi i64 [ %67, %58 ], [ %56, %55 ]
%60 = phi i64 [ %68, %58 ], [ 0, %55 ]
%61 = trunc i64 %59 to i32
%62 = getelementptr inbounds i8, i8* %10, i64 %59
%63 = load i8, i8* %62
%64 = add nsw i32 %15, %61
%65 = zext i32 %64 to i64
%66 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 %65
store i8 %63, i8* %66
%67 = add nuw nsw i64 %59, 1
%68 = add i64 %60, 1
%69 = icmp eq i64 %68, %18
br i1 %69, label %70, label %58
70: ; preds = %58, %55
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%72 = sub i32 %11, %14
%73 = icmp eq i32 %72, 0
br i1 %73, label %78, label %74
74: ; preds = %70
%75 = zext i32 %14 to i64
%76 = getelementptr inbounds i8, i8* %10, i64 %75
%77 = call i32 @putchar(i32 95)
br label %9
78: ; preds = %70
br label %79
79: ; preds = %78, %2
%80 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
ret void
}