#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 read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void capitalize(int s) {
  char line[80];
  while (1) {
    int received = read(s, line, 80);
    if (received == 0) {
      write(2, "connection closed\n", 18);
      break;
    } else if (received < 0) {
      write(2, "read error\n", 11);
      continue;
    }
    int i = 0;
    while (1) {
      if (!line[i] || i >= 80)
        break;
      if (line[i] >= 'a' && line[i] <= 'z')
        line[i] -= 0x20;
      i++;
    }
    write(s, line, received);
  }
}


x86 assembly (clang, -O0):
<capitalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x50,%edx
call   1040 <read@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jne    1164 <capitalize+0x44>
mov    $0x2,%edi
lea    0xeab(%rip),%rsi
mov    $0x12,%edx
call   1030 <write@plt>
jmp    1209 <capitalize+0xe9>
cmpl   $0x0,-0x64(%rbp)
jge    1189 <capitalize+0x69>
mov    $0x2,%edi
lea    0xe99(%rip),%rsi
mov    $0xb,%edx
call   1030 <write@plt>
jmp    112b <capitalize+0xb>
jmp    118e <capitalize+0x6e>
movl   $0x0,-0x68(%rbp)
movslq -0x68(%rbp),%rax
cmpb   $0x0,-0x60(%rbp,%rax,1)
je     11ae <capitalize+0x8e>
cmpl   $0x50,-0x68(%rbp)
jl     11b3 <capitalize+0x93>
jmp    11f5 <capitalize+0xd5>
movslq -0x68(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0x61,%eax
jl     11e7 <capitalize+0xc7>
movslq -0x68(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%eax
cmp    $0x7a,%eax
jg     11e7 <capitalize+0xc7>
movslq -0x68(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%ecx
sub    $0x20,%ecx
mov    %cl,-0x60(%rbp,%rax,1)
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1195 <capitalize+0x75>
mov    -0x4(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1030 <write@plt>
jmp    112b <capitalize+0xb>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<capitalize>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x50,%edx
call   1040 <read@plt>
test   %eax,%eax
je     11bf <capitalize+0x9f>
lea    0xecc(%rip),%r14
mov    %rsp,%r15
jmp    116f <capitalize+0x4f>
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x50,%edx
call   1040 <read@plt>
test   %eax,%eax
je     11bf <capitalize+0x9f>
test   %eax,%eax
js     11b0 <capitalize+0x90>
mov    (%rsp),%cl
test   %cl,%cl
je     1150 <capitalize+0x30>
xor    %edx,%edx
nopl   0x0(%rax)
lea    -0x61(%rcx),%esi
cmp    $0x19,%sil
ja     118f <capitalize+0x6f>
add    $0xe0,%cl
mov    %cl,(%rsp,%rdx,1)
movzbl 0x1(%rsp,%rdx,1),%ecx
test   %cl,%cl
je     1150 <capitalize+0x30>
lea    0x1(%rdx),%rsi
cmp    $0x4f,%rdx
mov    %rsi,%rdx
jb     1180 <capitalize+0x60>
jmp    1150 <capitalize+0x30>
nopw   0x0(%rax,%rax,1)
mov    $0x2,%edi
mov    %r14,%rsi
mov    $0xb,%edx
jmp    1157 <capitalize+0x37>
lea    0xe3a(%rip),%rsi
mov    $0x2,%edi
mov    $0x12,%edx
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <write@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"connection closed\0A\00"
@.str.1 = [12 x i8] c"read error\0A\00"
define void @capitalize(i32 %0) {
%2 = alloca i32
%3 = alloca [80 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
br label %6
6: ; preds = %1, %17, %56
%7 = load i32, i32* %2
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 80)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %6
%13 = call i32 @write(i32 2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 18)
br label %61
14: ; preds = %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @write(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
br label %6
19: ; preds = %14
br label %20
20: ; preds = %19
store i32 0, i32* %5
br label %21
21: ; preds = %20, %53
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32, i32* %5
%29 = icmp sge i32 %28, 80
br i1 %29, label %30, label %31
30: ; preds = %27, %21
br label %56
31: ; preds = %27
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp sge i32 %36, 97
br i1 %37, label %38, label %53
38: ; preds = %31
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp sle i32 %43, 122
br i1 %44, label %45, label %53
45: ; preds = %38
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = sub nsw i32 %50, 32
%52 = trunc i32 %51 to i8
store i8 %52, i8* %48
br label %53
53: ; preds = %45, %38, %31
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %21
56: ; preds = %30
%57 = load i32, i32* %2
%58 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%59 = load i32, i32* %4
%60 = call i32 @write(i32 %57, i8* %58, i32 %59)
br label %6
61: ; preds = %12
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"connection closed\0A\00"
@.str.1 = [12 x i8] c"read error\0A\00"
define void @capitalize(i32 %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 80)
%5 = icmp eq i32 %4, 0
br i1 %5, label %34, label %6
6: ; preds = %1, %31
%7 = phi i32 [ %32, %31 ], [ %4, %1 ]
%8 = icmp slt i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = load i8, i8* %3
%11 = icmp eq i8 %10, 0
br i1 %11, label %29, label %14
12: ; preds = %6
%13 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
br label %31
14: ; preds = %9, %22
%15 = phi i64 [ %23, %22 ], [ 0, %9 ]
%16 = phi i8 [ %25, %22 ], [ %10, %9 ]
%17 = phi i8* [ %24, %22 ], [ %3, %9 ]
%18 = add i8 %16, -97
%19 = icmp ult i8 %18, 26
br i1 %19, label %20, label %22
20: ; preds = %14
%21 = add nsw i8 %16, -32
store i8 %21, i8* %17
br label %22
22: ; preds = %20, %14
%23 = add nuw nsw i64 %15, 1
%24 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
%27 = icmp ugt i64 %15, 78
%28 = select i1 %26, i1 true, i1 %27
br i1 %28, label %29, label %14
29: ; preds = %22, %9
%30 = call i32 @write(i32 %0, i8* %3, i32 %7)
br label %31
31: ; preds = %29, %12
%32 = call i32 @read(i32 %0, i8* %3, i32 80)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %6
34: ; preds = %31, %1
%35 = tail call i32 @write(i32 2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 18)
ret void
}