#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 CHAR_BIT;
scalar_t__ isprint(unsigned char);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ putchar(char);
void strdump(const char *s) {
  while (*s) {
    int i;
    unsigned char x = (unsigned char)*s;
    printf("%c  ", isprint(x) ? x : ' ');
    printf("%0*X  ", (CHAR_BIT + 3) / 4, x);
    for (i = CHAR_BIT - 1; i >= 0; i--)
      putchar(((x >> i) & 1U) ? '1' : '0');
    putchar('\n');
    s++;
  }
}


x86 assembly (clang, -O0):
<strdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     121d <strdump+0xed>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     1171 <strdump+0x41>
movzbl -0xd(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    117e <strdump+0x4e>
mov    $0x20,%eax
mov    %eax,-0x14(%rbp)
jmp    117e <strdump+0x4e>
mov    -0x14(%rbp),%esi
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
add    $0x3,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
movzbl -0xd(%rbp),%edx
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1202 <strdump+0xd2>
movzbl -0xd(%rbp),%edx
mov    -0xc(%rbp),%ecx
sar    %cl,%edx
and    $0x1,%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11c6 <strdump+0x96>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    113c <strdump+0xc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     11f7 <strdump+0xc7>
mov    %rdi,%rbx
lea    0xeb1(%rip),%r14
mov    0x2e8a(%rip),%r13
lea    0xea8(%rip),%r15
jmp    1179 <strdump+0x49>
nop
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x1(%rbx),%al
add    $0x1,%rbx
test   %al,%al
je     11f7 <strdump+0xc7>
movzbl %al,%ebp
mov    %ebp,%edi
call   1050 <isprint@plt>
test   %rax,%rax
mov    %ebp,%esi
mov    $0x20,%eax
cmove  %eax,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%esi
lea    0x3(%rsi),%eax
add    $0x6,%esi
test   %eax,%eax
cmovns %eax,%esi
sar    $0x2,%esi
mov    %r15,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%r12d
test   %r12d,%r12d
jle    1160 <strdump+0x30>
add    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x2(%r12),%eax
movzbl %al,%eax
bt     %eax,%ebp
mov    $0x31,%edi
adc    $0xffffffff,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%r12d
cmp    $0x1,%r12d
ja     11d0 <strdump+0xa0>
jmp    1160 <strdump+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%c \00"
@.str.1 = [7 x i8] c"%0*X \00"
@CHAR_BIT = global i32 0
define void @strdump(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* %0, i8** %2
br label %5
5: ; preds = %47, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %51
9: ; preds = %5
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
store i8 %11, i8* %4
%12 = load i8, i8* %4
%13 = call i64 @isprint(i8 zeroext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = load i8, i8* %4
%17 = zext i8 %16 to i32
br label %19
18: ; preds = %9
br label %19
19: ; preds = %18, %15
%20 = phi i32 [ %17, %15 ], [ 32, %18 ]
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* @CHAR_BIT
%23 = add nsw i32 %22, 3
%24 = sdiv i32 %23, 4
%25 = load i8, i8* %4
%26 = zext i8 %25 to i32
%27 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %26)
%28 = load i32, i32* @CHAR_BIT
%29 = sub nsw i32 %28, 1
store i32 %29, i32* %3
br label %30
30: ; preds = %44, %19
%31 = load i32, i32* %3
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %47
33: ; preds = %30
%34 = load i8, i8* %4
%35 = zext i8 %34 to i32
%36 = load i32, i32* %3
%37 = ashr i32 %35, %36
%38 = and i32 %37, 1
%39 = icmp ne i32 %38, 0
%40 = zext i1 %39 to i64
%41 = select i1 %39, i32 49, i32 48
%42 = trunc i32 %41 to i8
%43 = call i32 @putchar(i8 signext %42)
br label %44
44: ; preds = %33
%45 = load i32, i32* %3
%46 = add nsw i32 %45, -1
store i32 %46, i32* %3
br label %30
47: ; preds = %30
%48 = call i32 @putchar(i8 signext 10)
%49 = load i8*, i8** %2
%50 = getelementptr inbounds i8, i8* %49, i32 1
store i8* %50, i8** %2
br label %5
51: ; preds = %5
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%c \00"
@.str.1 = [7 x i8] c"%0*X \00"
@CHAR_BIT = global i32 0
define void @strdump(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %32, label %4
4: ; preds = %1, %27
%5 = phi i8 [ %30, %27 ], [ %2, %1 ]
%6 = phi i8* [ %29, %27 ], [ %0, %1 ]
%7 = tail call i64 @isprint(i8 zeroext %5)
%8 = icmp eq i64 %7, 0
%9 = zext i8 %5 to i32
%10 = select i1 %8, i32 32, i32 %9
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @CHAR_BIT
%13 = add nsw i32 %12, 3
%14 = sdiv i32 %13, 4
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %9)
%16 = load i32, i32* @CHAR_BIT
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %4, %18
%19 = phi i32 [ %20, %18 ], [ %16, %4 ]
%20 = add nsw i32 %19, -1
%21 = shl nuw i32 1, %20
%22 = and i32 %21, %9
%23 = icmp eq i32 %22, 0
%24 = select i1 %23, i8 48, i8 49
%25 = tail call i32 @putchar(i8 signext %24)
%26 = icmp ugt i32 %19, 1
br i1 %26, label %18, label %27
27: ; preds = %18, %4
%28 = tail call i32 @putchar(i8 signext 10)
%29 = getelementptr inbounds i8, i8* %6, i64 1
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %4
32: ; preds = %27, %1
ret void
}