#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*/ printf(char *, ...);
int read(int, char *, int);
void *readThread(void *arg) {
  int sock = *((int *)arg);
  char message[20 + 1024];
  int strLength;
  while (1) {
    strLength = read(sock, message, 20 + 1024 - 1);
    if (strLength == -1) {
      printf("read from server error\n");
    } else if (strLength == 0) {
      return (void *)-1;
    }
    message[strLength] = 0;
    printf("%s", message);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<readThread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x413,%edx
call   1040 <read@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0xffffffff,-0x424(%rbp)
jne    1172 <readThread+0x52>
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1194 <readThread+0x74>
cmpl   $0x0,-0x424(%rbp)
jne    118f <readThread+0x6f>
mov    $0xffffffffffffffff,%rax
add    $0x430,%rsp
pop    %rbp
ret
jmp    1194 <readThread+0x74>
movslq -0x424(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1138 <readThread+0x18>

x86 assembly (clang, -O2):
<readThread>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x420,%rsp
mov    (%rdi),%r12d
mov    %rsp,%rbx
lea    0xeb7(%rip),%r14
lea    0xead(%rip),%r15
jmp    117c <readThread+0x4c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1030 <puts@plt>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x413,%edx
call   1050 <read@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1160 <readThread+0x30>
test   %ebp,%ebp
jne    1168 <readThread+0x38>
mov    $0xffffffffffffffff,%rax
add    $0x420,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"read from server error\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i8* @readThread(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [1044 x i8]
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
store i32 %8, i32* %3
br label %9
9: ; preds = %1, %22
%10 = load i32, i32* %3
%11 = getelementptr inbounds [1044 x i8], [1044 x i8]* %4, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 1043)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %22
17: ; preds = %9
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %17
ret i8* inttoptr (i64 -1 to i8*)
21: ; preds = %17
br label %22
22: ; preds = %21, %15
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1044 x i8], [1044 x i8]* %4, i64 0, i64 %24
store i8 0, i8* %25
%26 = getelementptr inbounds [1044 x i8], [1044 x i8]* %4, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %9
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@str = [23 x i8] c"read from server error\00"
define i8* @readThread(i8* nocapture %0) {
%2 = alloca [1044 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = getelementptr inbounds [1044 x i8], [1044 x i8]* %2, i64 0, i64 0
br label %6
6: ; preds = %11, %1
%7 = call i32 @read(i32 %4, i8* %5, i32 1043)
switch i32 %7, label %11 [
i32 -1, label %8
i32 0, label %10
]
8: ; preds = %6
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %11
10: ; preds = %6
ret i8* inttoptr (i64 -1 to i8*)
11: ; preds = %6, %8
%12 = sext i32 %7 to i64
%13 = getelementptr inbounds [1044 x i8], [1044 x i8]* %2, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %6
}