#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 */
char toupper(char);
int preprocess(char *s) {
  int n = 0;
  for (; *s; ++s, ++n) {
    if (*s == '\n' || *s == '\r') {
      *s = '\0';
      break;
    }
    *s = toupper(*s);
  }
  return n;
}


x86 assembly (clang, -O0):
<preprocess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     118a <preprocess+0x7a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1150 <preprocess+0x40>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    115c <preprocess+0x4c>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    118a <preprocess+0x7a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <preprocess+0x13>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<preprocess>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl (%r14,%rbx,1),%eax
test   %al,%al
je     1148 <preprocess+0x38>
cmp    $0xd,%al
je     1143 <preprocess+0x33>
cmp    $0xa,%al
je     1143 <preprocess+0x33>
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
jmp    1120 <preprocess+0x10>
movb   $0x0,(%r14,%rbx,1)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @preprocess(i8* nocapture %0) {
br label %2
2: ; preds = %7, %1
%3 = phi i8* [ %0, %1 ], [ %9, %7 ]
%4 = phi i32 [ 0, %1 ], [ %10, %7 ]
%5 = load i8, i8* %3
switch i8 %5, label %7 [
i8 0, label %11
i8 10, label %6
i8 13, label %6
]
6: ; preds = %2, %2
store i8 0, i8* %3
br label %11
7: ; preds = %2
%8 = tail call signext i8 @toupper(i8 signext %5)
store i8 %8, i8* %3
%9 = getelementptr inbounds i8, i8* %3, i64 1
%10 = add nuw nsw i32 %4, 1
br label %2
11: ; preds = %2, %6
ret i32 %4
}