#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 *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
void fn32(char *str) {
  char buf[32] = {0};
  char *cp = buf;
  int i, len, count;
  for (i = 0; str[i]; i++) {
    printf("%02x", (unsigned char)str[i]);
    if ((1 + i) % 32 == 0)
      printf("\n");
    else if ((1 + i) % 8 == 0)
      printf("   ");
    else if ((1 + i) % 4 == 0)
      printf(" ");
  }
  printf("\n\n");
  strcpy(cp, str);
  for (i = 0; buf[i]; i++) {
    printf("%02x", (unsigned char)buf[i]);
    if ((1 + i) % 32 == 0)
      printf("\n");
    else if ((1 + i) % 8 == 0)
      printf("   ");
    else if ((1 + i) % 4 == 0)
      printf(" ");
  }
  printf("\n\n");
}


x86 assembly (clang, -O0):
<fn32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1050 <memset@plt>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     121d <fn32+0xed>
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b1 <fn32+0x81>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120a <fn32+0xda>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11db <fn32+0xab>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1205 <fn32+0xd5>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1200 <fn32+0xd0>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1205 <fn32+0xd5>
jmp    120a <fn32+0xda>
jmp    120f <fn32+0xdf>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    115b <fn32+0x2b>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x3c(%rbp)
movslq -0x3c(%rbp),%rax
cmpb   $0x0,-0x30(%rbp,%rax,1)
je     12fb <fn32+0x1cb>
movslq -0x3c(%rbp),%rax
movzbl -0x30(%rbp,%rax,1),%esi
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    $0x20,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    128f <fn32+0x15f>
lea    0xd87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e8 <fn32+0x1b8>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12b9 <fn32+0x189>
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e3 <fn32+0x1b3>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12de <fn32+0x1ae>
lea    0xd30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12e3 <fn32+0x1b3>
jmp    12e8 <fn32+0x1b8>
jmp    12ed <fn32+0x1bd>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    123f <fn32+0x10f>
lea    0xd07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fn32>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r12
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    (%rdi),%al
test   %al,%al
je     11cc <fn32+0x8c>
mov    $0x1,%ebx
lea    0xe94(%rip),%r14
lea    0xe92(%rip),%r15
jmp    1197 <fn32+0x57>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl (%r12,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
je     11cc <fn32+0x8c>
movzbl %al,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   $0x1f,%bl
je     11c0 <fn32+0x80>
test   $0x7,%bl
je     1180 <fn32+0x40>
test   $0x3,%bl
jne    118a <fn32+0x4a>
mov    $0x20,%edi
jmp    11c5 <fn32+0x85>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    118a <fn32+0x4a>
lea    0xe36(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    (%rsp),%al
test   %al,%al
je     124c <fn32+0x10c>
mov    $0x1,%ebx
lea    0xe0a(%rip),%r15
lea    0xe08(%rip),%r14
jmp    1216 <fn32+0xd6>
nop
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
movzbl (%rsp,%rbx,1),%eax
add    $0x1,%rbx
test   %al,%al
je     124c <fn32+0x10c>
movzbl %al,%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
test   $0x1f,%bl
je     1240 <fn32+0x100>
test   $0x7,%bl
je     1200 <fn32+0xc0>
test   $0x3,%bl
jne    120a <fn32+0xca>
mov    $0x20,%edi
jmp    1245 <fn32+0x105>
nopl   0x0(%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    120a <fn32+0xca>
lea    0xdb6(%rip),%rdi
call   1050 <puts@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 = [3 x i8] c"\0A\0A\00"
define void @fn32(i8* %0) {
%2 = alloca i8*
%3 = alloca [32 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = bitcast [32 x i8]* %3 to i8*
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
store i8* %9, i8** %4
store i32 0, i32* %5
br label %10
10: ; preds = %48, %1
%11 = load i8*, i8** %2
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %51
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = zext i8 %22 to i32
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %5
%26 = add nsw i32 1, %25
%27 = srem i32 %26, 32
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %17
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %47
31: ; preds = %17
%32 = load i32, i32* %5
%33 = add nsw i32 1, %32
%34 = srem i32 %33, 8
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %31
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %46
38: ; preds = %31
%39 = load i32, i32* %5
%40 = add nsw i32 1, %39
%41 = srem i32 %40, 4
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38
%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, %38
br label %46
46: ; preds = %45, %36
br label %47
47: ; preds = %46, %29
br label %48
48: ; preds = %47
%49 = load i32, i32* %5
%50 = add nsw i32 %49, 1
store i32 %50, i32* %5
br label %10
51: ; preds = %10
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%53 = load i8*, i8** %4
%54 = load i8*, i8** %2
%55 = call i32 @strcpy(i8* %53, i8* %54)
store i32 0, i32* %5
br label %56
56: ; preds = %92, %51
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = icmp ne i8 %60, 0
br i1 %61, label %62, label %95
62: ; preds = %56
%63 = load i32, i32* %5
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 %64
%66 = load i8, i8* %65
%67 = zext i8 %66 to i32
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %67)
%69 = load i32, i32* %5
%70 = add nsw i32 1, %69
%71 = srem i32 %70, 32
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %62
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %91
75: ; preds = %62
%76 = load i32, i32* %5
%77 = add nsw i32 1, %76
%78 = srem i32 %77, 8
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %75
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %90
82: ; preds = %75
%83 = load i32, i32* %5
%84 = add nsw i32 1, %83
%85 = srem i32 %84, 4
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %82
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %89
89: ; preds = %87, %82
br label %90
90: ; preds = %89, %80
br label %91
91: ; preds = %90, %73
br label %92
92: ; preds = %91
%93 = load i32, i32* %5
%94 = add nsw i32 %93, 1
store i32 %94, i32* %5
br label %56
95: ; preds = %56
%96 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
@.str.2 = [4 x i8] c" \00"
@str.5 = [2 x i8] c"\0A\00"
define void @fn32(i8* %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %31, label %6
6: ; preds = %1, %27
%7 = phi i64 [ %11, %27 ], [ 0, %1 ]
%8 = phi i8 [ %29, %27 ], [ %4, %1 ]
%9 = zext i8 %8 to i32
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = add nuw i64 %7, 1
%12 = trunc i64 %11 to i32
%13 = and i32 %12, 31
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = tail call i32 @putchar(i32 10)
br label %27
17: ; preds = %6
%18 = and i32 %12, 7
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %27
22: ; preds = %17
%23 = and i32 %12, 3
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @putchar(i32 32)
br label %27
27: ; preds = %15, %22, %25, %20
%28 = getelementptr inbounds i8, i8* %0, i64 %11
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %31, label %6
31: ; preds = %27, %1
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
%33 = call i32 @strcpy(i8* %3, i8* %0)
%34 = load i8, i8* %3
%35 = icmp eq i8 %34, 0
br i1 %35, label %61, label %36
36: ; preds = %31, %57
%37 = phi i64 [ %41, %57 ], [ 0, %31 ]
%38 = phi i8 [ %59, %57 ], [ %34, %31 ]
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = add nuw i64 %37, 1
%42 = trunc i64 %41 to i32
%43 = and i32 %42, 31
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %36
%46 = call i32 @putchar(i32 10)
br label %57
47: ; preds = %36
%48 = and i32 %42, 7
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %52
50: ; preds = %47
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %57
52: ; preds = %47
%53 = and i32 %42, 3
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @putchar(i32 32)
br label %57
57: ; preds = %45, %52, %55, %50
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %41
%59 = load i8, i8* %58
%60 = icmp eq i8 %59, 0
br i1 %60, label %61, label %36
61: ; preds = %57, %31
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
ret void
}