#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 */
scalar_t__ is_char_bad(int);
int /*<<< orphan*/ putchar(char);
void print_clean_header(char *header, int length) {
  int i = 0;
  int c = 0;
  int last_printed = 0;
  for (i = 0; i < length; i++) {
    c = header[i];
    if (is_char_bad(c) && last_printed != '_') {
      putchar('_');
      last_printed = '_';
    } else if (!is_char_bad(c)) {
      putchar(c);
      last_printed = c;
    }
  }
  putchar('\n');
}


x86 assembly (clang, -O0):
<print_clean_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d3 <print_clean_header+0xb3>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <is_char_bad@plt>
cmp    $0x0,%rax
je     1198 <print_clean_header+0x78>
cmpl   $0x5f,-0x18(%rbp)
je     1198 <print_clean_header+0x78>
mov    $0x5f,%edi
call   1030 <putchar@plt>
movl   $0x5f,-0x18(%rbp)
jmp    11c0 <print_clean_header+0xa0>
mov    -0x14(%rbp),%edi
call   1040 <is_char_bad@plt>
cmp    $0x0,%rax
jne    11bb <print_clean_header+0x9b>
mov    -0x14(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    11c0 <print_clean_header+0xa0>
jmp    11c5 <print_clean_header+0xa5>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114b <print_clean_header+0x2b>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_clean_header>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1186 <print_clean_header+0x66>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
xor    %r12d,%r12d
jmp    115d <print_clean_header+0x3d>
nopl   0x0(%rax)
mov    $0x5f,%ebp
mov    $0x5f,%r13b
movsbl %r13b,%edi
call   1030 <putchar@plt>
mov    %ebp,%r12d
add    $0x1,%rbx
cmp    %rbx,%r15
je     1186 <print_clean_header+0x66>
movzbl (%r14,%rbx,1),%r13d
movsbl %r13b,%ebp
mov    %ebp,%edi
call   1040 <is_char_bad@plt>
test   %rax,%rax
je     1178 <print_clean_header+0x58>
cmp    $0x5f,%r12d
jne    1140 <print_clean_header+0x20>
mov    %ebp,%edi
call   1040 <is_char_bad@plt>
test   %rax,%rax
jne    1154 <print_clean_header+0x34>
jmp    1148 <print_clean_header+0x28>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
define void @print_clean_header(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %5
br label %8
8: ; preds = %38, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %41
12: ; preds = %8
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = call i64 @is_char_bad(i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %12
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 95
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @putchar(i8 signext 95)
store i32 95, i32* %7
br label %37
27: ; preds = %22, %12
%28 = load i32, i32* %6
%29 = call i64 @is_char_bad(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %36, label %31
31: ; preds = %27
%32 = load i32, i32* %6
%33 = trunc i32 %32 to i8
%34 = call i32 @putchar(i8 signext %33)
%35 = load i32, i32* %6
store i32 %35, i32* %7
br label %36
36: ; preds = %31, %27
br label %37
37: ; preds = %36, %25
br label %38
38: ; preds = %37
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %8
41: ; preds = %8
%42 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
define void @print_clean_header(i8* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %27
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %23
%7 = phi i64 [ 0, %4 ], [ %25, %23 ]
%8 = phi i32 [ 0, %4 ], [ %24, %23 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = tail call i64 @is_char_bad(i32 %11)
%13 = icmp ne i64 %12, 0
%14 = icmp ne i32 %8, 95
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %19, label %16
16: ; preds = %6
%17 = tail call i64 @is_char_bad(i32 %11)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16, %6
%20 = phi i8 [ 95, %6 ], [ %10, %16 ]
%21 = phi i32 [ 95, %6 ], [ %11, %16 ]
%22 = tail call i32 @putchar(i8 signext %20)
br label %23
23: ; preds = %19, %16
%24 = phi i32 [ %8, %16 ], [ %21, %19 ]
%25 = add nuw nsw i64 %7, 1
%26 = icmp eq i64 %25, %5
br i1 %26, label %27, label %6
27: ; preds = %23, %2
%28 = tail call i32 @putchar(i8 signext 10)
ret void
}