#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int read(int, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
char toupper(char);
int /*<<< orphan*/ write(int, char *, int);
void *fun(void *p) {
  int c = (int)p;
  char buf[1024];
  for (;;) {
    int n = read(c, buf, sizeof(buf) - 1);
    if (n <= 0)
      break;
    buf[n] = '\0';
    if (!strcmp(buf, "bye\n") || !strcmp(buf, "bye\r\n"))
      break;
    int i;
    write(1, buf, n);
    for (i = 0; i < n; i++)
      buf[i] = toupper(buf[i]);
    write(c, buf, n);
  }
  close(c);
  return 0;
}


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jg     1192 <fun+0x42>
jmp    1263 <fun+0x113>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     11d9 <fun+0x89>
lea    -0x410(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11de <fun+0x8e>
jmp    1263 <fun+0x113>
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
movl   $0x0,-0x418(%rbp)
mov    -0x418(%rbp),%eax
cmp    -0x414(%rbp),%eax
jge    1249 <fun+0xf9>
movslq -0x418(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%edi
ff
call   1030 <toupper@plt>
mov    %al,%cl
movslq -0x418(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    11ff <fun+0xaf>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   1040 <write@plt>
jmp    1166 <fun+0x16>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rdi,%r15
mov    %rsp,%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11f6 <fun+0xb6>
mov    $0xa657962,%r13d
mov    $0xd657962,%r12d
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
mov    %eax,%ebx
movb   $0x0,(%rsp,%rbx,1)
mov    (%rsp),%eax
xor    %r13d,%eax
movzbl 0x4(%rsp),%ecx
or     %eax,%ecx
je     11f6 <fun+0xb6>
mov    (%rsp),%eax
xor    %r12d,%eax
movzwl 0x4(%rsp),%ecx
xor    $0xa,%ecx
or     %eax,%ecx
je     11f6 <fun+0xb6>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsbl (%rsp,%rbp,1),%edi
call   1030 <toupper@plt>
mov    %al,(%rsp,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11c0 <fun+0x80>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x3ff,%edx
call   1060 <read@plt>
test   %eax,%eax
jg     1180 <fun+0x40>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"bye\0A\00"
@.str.1 = [6 x i8] c"bye\0D\0A\00"
define i8* @fun(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = ptrtoint i8* %7 to i32
store i32 %8, i32* %3
br label %9
9: ; preds = %48, %1
%10 = load i32, i32* %3
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 1023)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp sle i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
br label %53
16: ; preds = %9
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%25 = call i32 @strcmp(i8* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %23, %16
br label %53
28: ; preds = %23
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%30 = load i32, i32* %5
%31 = call i32 @write(i32 1, i8* %29, i32 %30)
store i32 0, i32* %6
br label %32
32: ; preds = %45, %28
%33 = load i32, i32* %6
%34 = load i32, i32* %5
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = call signext i8 @toupper(i8 signext %40)
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %43
store i8 %41, i8* %44
br label %45
45: ; preds = %36
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %32
48: ; preds = %32
%49 = load i32, i32* %3
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%51 = load i32, i32* %5
%52 = call i32 @write(i32 %49, i8* %50, i32 %51)
br label %9
53: ; preds = %27, %15
%54 = load i32, i32* %3
%55 = call i32 @close(i32 %54)
ret i8* null
}

LLVM IR (-O2):
@.str = [5 x i8] c"bye\0A\00"
@.str.1 = [6 x i8] c"bye\0D\0A\00"
define noalias i8* @fun(i8* %0) {
%2 = alloca [1024 x i8]
%3 = ptrtoint i8* %0 to i64
%4 = trunc i64 %3 to i32
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = call i32 @read(i32 %4, i8* %5, i32 1023)
%7 = icmp slt i32 %6, 1
br i1 %7, label %30, label %8
8: ; preds = %1, %26
%9 = phi i32 [ %28, %26 ], [ %6, %1 ]
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @bcmp(i8* dereferenceable(5) %5, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5)
%13 = icmp eq i32 %12, 0
br i1 %13, label %30, label %14
14: ; preds = %8
%15 = call i32 @bcmp(i8* dereferenceable(6) %5, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 6)
%16 = icmp eq i32 %15, 0
br i1 %16, label %30, label %17
17: ; preds = %14
%18 = call i32 @write(i32 1, i8* %5, i32 %9)
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %24, %19 ]
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = tail call signext i8 @toupper(i8 signext %22)
store i8 %23, i8* %21
%24 = add nuw nsw i64 %20, 1
%25 = icmp eq i64 %24, %10
br i1 %25, label %26, label %19
26: ; preds = %19
%27 = call i32 @write(i32 %4, i8* %5, i32 %9)
%28 = call i32 @read(i32 %4, i8* %5, i32 1023)
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %8
30: ; preds = %8, %14, %26, %1
%31 = tail call i32 @close(i32 %4)
ret i8* null
}