#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 strlen(char *);
void correct_string(char *str) {
  int len = strlen(str);
  int i;
  for (i = 0; i < len; i++) {
    if (str[i] < 32 && str[i] > 0) {
      str[i] = '\0';
      break;
    }
  }
  str[len] = '\0';
}


x86 assembly (clang, -O0):
<correct_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1189 <correct_string+0x79>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jge    1176 <correct_string+0x66>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jle    1176 <correct_string+0x66>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1189 <correct_string+0x79>
jmp    117b <correct_string+0x6b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112f <correct_string+0x1f>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<correct_string>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    114d <correct_string+0x3d>
mov    %eax,%ecx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14,%rdx,1),%ebx
add    $0xff,%bl
cmp    $0x1e,%bl
jbe    1148 <correct_string+0x38>
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1130 <correct_string+0x20>
jmp    114d <correct_string+0x3d>
movb   $0x0,(%r14,%rdx,1)
cltq
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @correct_string(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %18
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %15
%7 = phi i64 [ 0, %4 ], [ %16, %15 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = add i8 %9, -1
%11 = icmp ult i8 %10, 31
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = and i64 %7, 4294967295
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 0, i8* %14
br label %18
15: ; preds = %6
%16 = add nuw nsw i64 %7, 1
%17 = icmp eq i64 %16, %5
br i1 %17, label %18, label %6
18: ; preds = %15, %1, %12
%19 = sext i32 %2 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
store i8 0, i8* %20
ret void
}