#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 *, char);
void printf_underscored(const char *string) {
  char c;
  while (!((c = *string++) == '\0')) {
    printf("%c", (c == ' ' ? '_' : c));
  }
}


x86 assembly (clang, -O0):
<printf_underscored>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x9(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
sete   %al
xor    $0xff,%al
test   $0x1,%al
jne    1148 <printf_underscored+0x38>
jmp    1180 <printf_underscored+0x70>
movsbl -0x9(%rbp),%eax
cmp    $0x20,%eax
jne    1162 <printf_underscored+0x52>
mov    $0x5f,%eax
mov    %eax,-0x10(%rbp)
jmp    1169 <printf_underscored+0x59>
movsbl -0x9(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
lea    0xe8d(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
jmp    111c <printf_underscored+0xc>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf_underscored>:
push   %rbp
push   %r14
push   %rbx
mov    (%rdi),%al
test   %al,%al
je     114e <printf_underscored+0x3e>
mov    %rdi,%rbx
add    $0x1,%rbx
mov    $0x5f,%ebp
lea    0xed3(%rip),%r14
nopl   (%rax)
cmp    $0x20,%al
movzbl %al,%eax
cmove  %ebp,%eax
movsbl %al,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <printf_underscored+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @printf_underscored(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
store i8* %0, i8** %2
br label %4
4: ; preds = %19, %1
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i32 1
store i8* %6, i8** %2
%7 = load i8, i8* %5
store i8 %7, i8* %3
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 0
%10 = xor i1 %9, true
br i1 %10, label %11, label %23
11: ; preds = %4
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 32
br i1 %14, label %15, label %16
15: ; preds = %11
br label %19
16: ; preds = %11
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
br label %19
19: ; preds = %16, %15
%20 = phi i32 [ 95, %15 ], [ %18, %16 ]
%21 = trunc i32 %20 to i8
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %21)
br label %4
23: ; preds = %4
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @printf_underscored(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %13, label %4
4: ; preds = %1, %4
%5 = phi i8 [ %11, %4 ], [ %2, %1 ]
%6 = phi i8* [ %7, %4 ], [ %0, %1 ]
%7 = getelementptr inbounds i8, i8* %6, i64 1
%8 = icmp eq i8 %5, 32
%9 = select i1 %8, i8 95, i8 %5
%10 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %9)
%11 = load i8, i8* %7
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %4
13: ; preds = %4, %1
ret void
}