#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*/ fputs(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
void *recv_msg(void *arg) {
  int fd = *((int *)arg);
  char buf[20 + 128];
  int str_len;
  while (1) {
    str_len = read(fd, buf, sizeof(buf) - 1);
    if (str_len <= 0)
      return (void *)-1;
    buf[str_len] = '\0';
    fputs(buf, stdout);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<recv_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x93,%edx
call   1040 <read@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
jg     116f <recv_msg+0x4f>
mov    $0xffffffffffffffff,%rax
add    $0xb0,%rsp
pop    %rbp
ret
movslq -0xa4(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
jmp    1138 <recv_msg+0x18>

x86 assembly (clang, -O2):
<recv_msg>:
push   %rbp
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    (%rdi),%ebp
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x93,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1174 <recv_msg+0x54>
mov    0x2e99(%rip),%r14
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    (%r14),%esi
mov    %rbx,%rdi
call   1030 <fputs@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x93,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1150 <recv_msg+0x30>
mov    $0xffffffffffffffff,%rax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
define i8* @recv_msg(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [148 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, %16
%10 = load i32, i32* %3
%11 = getelementptr inbounds [148 x i8], [148 x i8]* %4, i64 0, i64 0
%12 = call i32 @read(i32 %10, i8* %11, i32 147)
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
ret i8* inttoptr (i64 -1 to i8*)
16: ; preds = %9
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [148 x i8], [148 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [148 x i8], [148 x i8]* %4, i64 0, i64 0
%21 = load i32, i32* @stdout
%22 = call i32 @fputs(i8* %20, i32 %21)
br label %9
}

LLVM IR (-O2):
@stdout = global i32 0
define i8* @recv_msg(i8* nocapture %0) {
%2 = alloca [148 x i8]
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = getelementptr inbounds [148 x i8], [148 x i8]* %2, i64 0, i64 0
%6 = call i32 @read(i32 %4, i8* %5, i32 147)
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %9, %1
ret i8* inttoptr (i64 -1 to i8*)
9: ; preds = %1, %9
%10 = phi i32 [ %15, %9 ], [ %6, %1 ]
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds [148 x i8], [148 x i8]* %2, i64 0, i64 %11
store i8 0, i8* %12
%13 = load i32, i32* @stdout
%14 = call i32 @fputs(i8* %5, i32 %13)
%15 = call i32 @read(i32 %4, i8* %5, i32 147)
%16 = icmp slt i32 %15, 1
br i1 %16, label %8, label %9
}