#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*/ exit(int);
scalar_t__ islower(char);
int /*<<< orphan*/ printf(char *, char *);
int read(int /*<<< orphan*/, char *, int);
scalar_t__ write(int /*<<< orphan*/, char *, int);
int main() {
  char buffer[128];
  int n, i;
  n = read(0, buffer, 128);
  for (i = 0; i < n; i++)
    if (islower(buffer[i]))
      buffer[i] = buffer[i] - 32;
  if (write(0, buffer, n) < 0) {
    printf("%s\n", "write() error");
    exit(1);
  };
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rsi
xor    %edi,%edi
mov    $0x80,%edx
call   1060 <read@plt>
mov    %eax,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%eax
cmp    -0x94(%rbp),%eax
jge    11f0 <main+0xa0>
movslq -0x98(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%edi
ff
call   1030 <islower@plt>
cmp    $0x0,%rax
je     11d7 <main+0x87>
movslq -0x98(%rbp),%rax
movsbl -0x90(%rbp,%rax,1),%eax
ff
sub    $0x20,%eax
mov    %al,%cl
movslq -0x98(%rbp),%rax
mov    %cl,-0x90(%rbp,%rax,1)
jmp    11dc <main+0x8c>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    1185 <main+0x35>
lea    -0x90(%rbp),%rsi
mov    -0x94(%rbp),%edx
xor    %edi,%edi
call   1040 <write@plt>
cmp    $0x0,%rax
jge    122b <main+0xdb>
lea    0xdeb(%rip),%rdi
lea    0xde8(%rip),%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x80,%edx
call   1060 <read@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    11a2 <main+0x52>
mov    %r14d,%r15d
xor    %ebp,%ebp
jmp    1189 <main+0x39>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     11a2 <main+0x52>
movzbl (%rsp,%rbp,1),%ebx
movsbl %bl,%edi
call   1030 <islower@plt>
test   %rax,%rax
je     1180 <main+0x30>
add    $0xe0,%bl
mov    %bl,(%rsp,%rbp,1)
jmp    1180 <main+0x30>
mov    %rsp,%rsi
xor    %edi,%edi
mov    %r14d,%edx
call   1040 <write@plt>
test   %rax,%rax
js     11c4 <main+0x74>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe35(%rip),%rdi
lea    0xe32(%rip),%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [14 x i8] c"write() error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = call i32 @read(i32 0, i8* %5, i32 128)
store i32 %6, i32* %3
store i32 0, i32* %4
br label %7
7: ; preds = %30, %0
%8 = load i32, i32* %4
%9 = load i32, i32* %3
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %33
11: ; preds = %7
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = call i64 @islower(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %11
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = sub nsw i32 %23, 32
%25 = trunc i32 %24 to i8
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %27
store i8 %25, i8* %28
br label %29
29: ; preds = %18, %11
br label %30
30: ; preds = %29
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %7
33: ; preds = %7
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%35 = load i32, i32* %3
%36 = call i64 @write(i32 0, i8* %34, i32 %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %33
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [14 x i8] c"write() error\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i32 @read(i32 0, i8* %2, i32 128)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %0
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %15
%8 = phi i64 [ 0, %5 ], [ %16, %15 ]
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %8
%10 = load i8, i8* %9
%11 = tail call i64 @islower(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = add i8 %10, -32
store i8 %14, i8* %9
br label %15
15: ; preds = %7, %13
%16 = add nuw nsw i64 %8, 1
%17 = icmp eq i64 %16, %6
br i1 %17, label %18, label %7
18: ; preds = %15, %0
%19 = call i64 @write(i32 0, i8* %2, i32 %3)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %18
ret i32 0
}