#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 *);
char *noctrl(char *buffer) {
  int len, i;
  unsigned char *p;
  if ((p = (unsigned char *)buffer) == NULL)
    return (NULL);
  len = strlen((char *)p);
  for (i = len - 1; i >= 0; i--) {
    if (p[i] <= 32)
      p[i] = '\0';
    else
      break;
  }
  return ((char *)p);
}


x86 assembly (clang, -O0):
<noctrl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    113b <noctrl+0x2b>
movq   $0x0,-0x8(%rbp)
jmp    11a0 <noctrl+0x90>
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1198 <noctrl+0x88>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jg     1180 <noctrl+0x70>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1185 <noctrl+0x75>
jmp    1198 <noctrl+0x88>
jmp    118a <noctrl+0x7a>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1150 <noctrl+0x40>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<noctrl>:
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     1147 <noctrl+0x37>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1147 <noctrl+0x37>
mov    %eax,%eax
add    $0x1,%rax
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rax),%ecx
cmpb   $0x20,(%rbx,%rcx,1)
ja     1147 <noctrl+0x37>
movb   $0x0,(%rbx,%rcx,1)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
ja     1130 <noctrl+0x20>
mov    %rbx,%rax
pop    %rbx
ret

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

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