#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*/ strchr(char *, char);
unsigned int strlen(char *);
int /*<<< orphan*/ strtolower(char *, unsigned int);
void normalize(char *buf) {
  char *ptr;
  unsigned int len;
  len = strlen(buf);
  ptr = buf + len - 1;
  while (ptr > buf) {
    if (!strchr(" \t\r\n", *ptr))
      break;
    *ptr-- = 0;
  }
  strtolower(buf, len);
}


x86 assembly (clang, -O0):
<normalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    11a0 <normalize+0x70>
mov    -0x10(%rbp),%rax
lea    0xe8d(%rip),%rdi
movsbl (%rax),%esi
call   1050 <strchr@plt>
cmp    $0x0,%eax
jne    1189 <normalize+0x59>
jmp    11a0 <normalize+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
jmp    115a <normalize+0x2a>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <strtolower@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %eax,%eax
lea    (%rbx,%rax,1),%rbp
add    $0xffffffffffffffff,%rbp
cmp    %rbx,%rbp
jbe    117d <normalize+0x4d>
lea    0xea8(%rip),%r15
nopl   0x0(%rax,%rax,1)
movsbl 0x0(%rbp),%esi
mov    %r15,%rdi
call   1050 <strchr@plt>
test   %eax,%eax
je     117d <normalize+0x4d>
movb   $0x0,0x0(%rbp)
add    $0xffffffffffffffff,%rbp
cmp    %rbx,%rbp
ja     1160 <normalize+0x30>
mov    %rbx,%rdi
mov    %r14d,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <strtolower@plt>

LLVM IR (-O0):
@.str = [5 x i8] c" \09\0D\0A\00"
define void @normalize(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %4
%7 = load i8*, i8** %2
%8 = load i32, i32* %4
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -1
store i8* %11, i8** %3
br label %12
12: ; preds = %22, %1
%13 = load i8*, i8** %3
%14 = load i8*, i8** %2
%15 = icmp ugt i8* %13, %14
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = load i8, i8* %17
%19 = call i32 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %16
br label %25
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %3
store i8 0, i8* %23
br label %12
25: ; preds = %21, %12
%26 = load i8*, i8** %2
%27 = load i32, i32* %4
%28 = call i32 @strtolower(i8* %26, i32 %27)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c" \09\0D\0A\00"
define void @normalize(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = zext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -1
%6 = icmp ugt i8* %5, %0
br i1 %6, label %7, label %15
7: ; preds = %1, %12
%8 = phi i8* [ %13, %12 ], [ %5, %1 ]
%9 = load i8, i8* %8
%10 = tail call i32 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
store i8 0, i8* %8
%13 = getelementptr inbounds i8, i8* %8, i64 -1
%14 = icmp ugt i8* %13, %0
br i1 %14, label %7, label %15
15: ; preds = %12, %7, %1
%16 = tail call i32 @strtolower(i8* %0, i32 %2)
ret void
}