#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__ iscntrl(unsigned char);
int remove_control_chars(char *str) {
  int i;
  int change = 0;
  for (i = 0; str[i]; i++) {
    if (iscntrl((unsigned char)(str[i]))) {
      str[i] = '_';
      change = 1;
    }
  }
  return change;
}


x86 assembly (clang, -O0):
<remove_control_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     117d <remove_control_chars+0x6d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1030 <iscntrl@plt>
cmp    $0x0,%rax
je     116a <remove_control_chars+0x5a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
movl   $0x1,-0x10(%rbp)
jmp    116f <remove_control_chars+0x5f>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    112a <remove_control_chars+0x1a>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_control_chars>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%al
test   %al,%al
je     1153 <remove_control_chars+0x43>
mov    %rdi,%rbx
add    $0x1,%rbx
xor    %ebp,%ebp
jmp    113b <remove_control_chars+0x2b>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1155 <remove_control_chars+0x45>
movzbl %al,%edi
call   1030 <iscntrl@plt>
test   %rax,%rax
je     1130 <remove_control_chars+0x20>
movb   $0x5f,-0x1(%rbx)
mov    $0x1,%ebp
jmp    1130 <remove_control_chars+0x20>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @remove_control_chars(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %5
5: ; preds = %26, %1
%6 = load i8*, i8** %2
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %29
12: ; preds = %5
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = call i64 @iscntrl(i8 zeroext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %12
%21 = load i8*, i8** %2
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 95, i8* %24
store i32 1, i32* %4
br label %25
25: ; preds = %20, %12
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %5
29: ; preds = %5
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
define i32 @remove_control_chars(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %18, label %4
4: ; preds = %1, %12
%5 = phi i64 [ %14, %12 ], [ 0, %1 ]
%6 = phi i8 [ %16, %12 ], [ %2, %1 ]
%7 = phi i8* [ %15, %12 ], [ %0, %1 ]
%8 = phi i32 [ %13, %12 ], [ 0, %1 ]
%9 = tail call i64 @iscntrl(i8 zeroext %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %4
store i8 95, i8* %7
br label %12
12: ; preds = %4, %11
%13 = phi i32 [ 1, %11 ], [ %8, %4 ]
%14 = add nuw i64 %5, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %4
18: ; preds = %12, %1
%19 = phi i32 [ 0, %1 ], [ %13, %12 ]
ret i32 %19
}