#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 *, char *);
int read(int, char *, int);
void read_routine(int sock) {
  char buff[1024];
  int str_len;
  while (1) {
    str_len = read(sock, buff, 1024);
    if (str_len < 1)
      return;
    buff[str_len] = 0;
    printf("Message from server : %s \n", buff);
  }
}


x86 assembly (clang, -O0):
<read_routine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x1,-0x414(%rbp)
jge    115e <read_routine+0x3e>
add    $0x420,%rsp
pop    %rbp
ret
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xe85(%rip),%rdi
call   1030 <printf@plt>
jmp    112e <read_routine+0xe>

x86 assembly (clang, -O2):
<read_routine>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ebp
mov    %rsp,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1174 <read_routine+0x54>
lea    0xebb(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1150 <read_routine+0x30>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Message from server : %s \0A\00"
define void @read_routine(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %1, %12
%6 = load i32, i32* %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 1024)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %5
ret void
12: ; preds = %5
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %14
store i8 0, i8* %15
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %5
}

LLVM IR (-O2):
@.str = [27 x i8] c"Message from server : %s \0A\00"
define void @read_routine(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = call i32 @read(i32 %0, i8* %3, i32 1024)
%5 = icmp slt i32 %4, 1
br i1 %5, label %6, label %7
6: ; preds = %7, %1
ret void
7: ; preds = %1, %7
%8 = phi i32 [ %12, %7 ], [ %4, %1 ]
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %3)
%12 = call i32 @read(i32 %0, i8* %3, i32 1024)
%13 = icmp slt i32 %12, 1
br i1 %13, label %6, label %7
}