#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 fn3(char *str) {
  char buf = {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);
}


x86 assembly (clang, -O0):
<fn3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
mov    $0x0,%al
call   1050 <esp@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
lea    -0x9(%rbp),%rdi
call   1060 <memcpy@plt>
lea    -0x9(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1237 <fn3+0xf7>
mov    -0x18(%rbp),%rax
movzbl (%rax),%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
and    $0xf,%rax
cmp    $0x0,%rax
jne    11ca <fn3+0x8a>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1221 <fn3+0xe1>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
and    $0x7,%rax
cmp    $0x0,%rax
jne    11f3 <fn3+0xb3>
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121c <fn3+0xdc>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
and    $0x3,%rax
cmp    $0x0,%rax
jne    1217 <fn3+0xd7>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121c <fn3+0xdc>
jmp    1221 <fn3+0xe1>
jmp    1226 <fn3+0xe6>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    117f <fn3+0x3f>
lea    0xdd1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x9(%rbp),%rsi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fn3>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
movb   $0x0,(%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     11ec <fn3+0x9c>
lea    0x1(%rsp),%r12
lea    0xe72(%rip),%r15
lea    0xe70(%rip),%r14
mov    %r12,%rbx
jmp    11bb <fn3+0x6b>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl (%r12),%eax
add    $0x1,%rbx
add    $0x1,%r12
test   %al,%al
je     11ec <fn3+0x9c>
movzbl %al,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
test   $0xf,%bl
je     11e0 <fn3+0x90>
test   $0x7,%bl
je     11a0 <fn3+0x50>
test   $0x3,%bl
jne    11aa <fn3+0x5a>
mov    $0x20,%edi
jmp    11e5 <fn3+0x95>
xchg   %ax,%ax
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    11aa <fn3+0x5a>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    (%rsp),%rsi
lea    0xe08(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x8,%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 @fn3(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8*
store i8* %0, i8** %2
store i8 0, i8* %3
%5 = call i32 (...) @esp()
%6 = load i8*, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = call i32 @memcpy(i8* %3, i8* %6, i32 %8)
store i8* %3, i8** %4
br label %10
10: ; preds = %45, %1
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
br i1 %13, label %14, label %48
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %4
%20 = ptrtoint i8* %19 to i64
%21 = add i64 %20, 1
%22 = urem i64 %21, 16
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %44
26: ; preds = %14
%27 = load i8*, i8** %4
%28 = ptrtoint i8* %27 to i64
%29 = add i64 %28, 1
%30 = urem i64 %29, 8
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %43
34: ; preds = %26
%35 = load i8*, i8** %4
%36 = ptrtoint i8* %35 to i64
%37 = add i64 %36, 1
%38 = urem i64 %37, 4
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %42
42: ; preds = %40, %34
br label %43
43: ; preds = %42, %32
br label %44
44: ; preds = %43, %24
br label %45
45: ; preds = %44
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %4
br label %10
48: ; preds = %10
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%50 = bitcast i8* %3 to i64*
%51 = load i64, i64* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i64 %51)
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 @fn3(i8* %0) {
%2 = alloca i8
store i8 0, i8* %2
%3 = tail call i32 (...) @esp()
%4 = tail call i32 @strlen(i8* %0)
%5 = call i32 @memcpy(i8* %2, i8* %0, i32 %4)
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %33, label %8
8: ; preds = %1, %29
%9 = phi i8 [ %31, %29 ], [ %6, %1 ]
%10 = phi i8* [ %30, %29 ], [ %2, %1 ]
%11 = zext i8 %9 to i32
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = ptrtoint i8* %10 to i64
%14 = add i64 %13, 1
%15 = and i64 %14, 15
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %8
%18 = call i32 @putchar(i32 10)
br label %29
19: ; preds = %8
%20 = and i64 %14, 7
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %29
24: ; preds = %19
%25 = and i64 %14, 3
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = call i32 @putchar(i32 32)
br label %29
29: ; preds = %17, %24, %27, %22
%30 = getelementptr inbounds i8, i8* %10, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %8
33: ; preds = %29, %1
%34 = call i32 @putchar(i32 10)
%35 = bitcast i8* %2 to i64*
%36 = load i64, i64* %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i64 %36)
ret void
}