#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*/ esp();
int /*<<< orphan*/ memcpy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char *);
void fn2(char *str) {
  char buf[32] = {0};
  char *cp;
  esp();
  memcpy(buf, str, strlen(str));
  for (cp = buf; *cp; cp++) {
    printf("%02x", (unsigned char)*cp);
    if (((unsigned long)cp + 1) % 16 == 0) {
      printf("\n");
    } else if (((unsigned long)cp + 1) % 8 == 0) {
      printf("   ");
    } else if (((unsigned long)cp + 1) % 4 == 0) {
      printf(" ");
    }
  }
  printf("\n");
  printf("%016lx\n", *(unsigned long *)&buf[40]);
}


x86 assembly (clang, -O0):
<fn2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    $0x0,%al
call   1050 <esp@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmpb   $0x0,(%rax)
je     125b <fn2+0x10b>
mov    -0x38(%rbp),%rax
movzbl (%rax),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    11ee <fn2+0x9e>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1245 <fn2+0xf5>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    1217 <fn2+0xc7>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1240 <fn2+0xf0>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
and    $0x3,%rax
cmp    $0x0,%rax
jne    123b <fn2+0xeb>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1240 <fn2+0xf0>
jmp    1245 <fn2+0xf5>
jmp    124a <fn2+0xfa>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11a3 <fn2+0x53>
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fn2>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1060 <esp@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1070 <memcpy@plt>
mov    (%rsp),%al
test   %al,%al
je     11fc <fn2+0xac>
lea    0x1(%rsp),%r12
lea    0xe67(%rip),%r15
lea    0xe65(%rip),%r14
mov    %r12,%rbx
jmp    11cb <fn2+0x7b>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl (%r12),%eax
add    $0x1,%rbx
add    $0x1,%r12
test   %al,%al
je     11fc <fn2+0xac>
movzbl %al,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0xf,%bl
je     11f0 <fn2+0xa0>
test   $0x7,%bl
je     11b0 <fn2+0x60>
test   $0x3,%bl
jne    11ba <fn2+0x6a>
mov    $0x20,%edi
jmp    11f5 <fn2+0xa5>
xchg   %ax,%ax
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11ba <fn2+0x6a>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x28(%rsp),%rsi
lea    0xdf7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
@.str.2 = [4 x i8] c" \00"
@.str.4 = [8 x i8] c"%016lx\0A\00"
define void @fn2(i8* %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = tail call i32 (...) @esp()
%5 = tail call i32 @strlen(i8* %0)
%6 = call i32 @memcpy(i8* %3, i8* %0, i32 %5)
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 0
br i1 %8, label %34, label %9
9: ; preds = %1, %30
%10 = phi i8 [ %32, %30 ], [ %7, %1 ]
%11 = phi i8* [ %31, %30 ], [ %3, %1 ]
%12 = zext i8 %10 to i32
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = ptrtoint i8* %11 to i64
%15 = add i64 %14, 1
%16 = and i64 %15, 15
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = call i32 @putchar(i32 10)
br label %30
20: ; preds = %9
%21 = and i64 %15, 7
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %30
25: ; preds = %20
%26 = and i64 %15, 3
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @putchar(i32 32)
br label %30
30: ; preds = %18, %25, %28, %23
%31 = getelementptr inbounds i8, i8* %11, i64 1
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %9
34: ; preds = %30, %1
%35 = call i32 @putchar(i32 10)
%36 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 40
%37 = bitcast i8* %36 to i64*
%38 = load i64, i64* %37
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i64 %38)
ret void
}