#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int readline(int, char *, int);
int /*<<< orphan*/ stdout;
int recv_msg(int from) {
  char buf[3000];
  int len;
  if ((len = readline(from, buf, sizeof(buf) - 1)) < 0)
    return -1;
  buf[len] = 0;
  printf("%s", buf);
  fflush(stdout);
  return len;
}


x86 assembly (clang, -O0):
<recv_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0xbd0,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xbc0(%rbp),%rsi
mov    $0xbb7,%edx
call   1040 <readline@plt>
mov    %eax,-0xbc4(%rbp)
cmp    $0x0,%eax
jge    116d <recv_msg+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a6 <recv_msg+0x76>
movslq -0xbc4(%rbp),%rax
movb   $0x0,-0xbc0(%rbp,%rax,1)
lea    -0xbc0(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0xbc4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xbd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recv_msg>:
push   %rbx
sub    $0xbc0,%rsp
mov    %rsp,%rsi
mov    $0xbb7,%edx
call   1040 <readline@plt>
test   %eax,%eax
js     1170 <recv_msg+0x40>
mov    %eax,%ebx
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xea8(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    1175 <recv_msg+0x45>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0xbc0,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stdout = global i32 0
define i32 @recv_msg(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [3000 x i8]
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = getelementptr inbounds [3000 x i8], [3000 x i8]* %4, i64 0, i64 0
%8 = call i32 @readline(i32 %6, i8* %7, i32 2999)
store i32 %8, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 -1, i32* %2
br label %20
11: ; preds = %1
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [3000 x i8], [3000 x i8]* %4, i64 0, i64 %13
store i8 0, i8* %14
%15 = getelementptr inbounds [3000 x i8], [3000 x i8]* %4, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @stdout
%18 = call i32 @fflush(i32 %17)
%19 = load i32, i32* %5
store i32 %19, i32* %2
br label %20
20: ; preds = %11, %10
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdout = global i32 0
define i32 @recv_msg(i32 %0) {
%2 = alloca [3000 x i8]
%3 = getelementptr inbounds [3000 x i8], [3000 x i8]* %2, i64 0, i64 0
%4 = call i32 @readline(i32 %0, i8* %3, i32 2999)
%5 = icmp slt i32 %4, 0
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = zext i32 %4 to i64
%8 = getelementptr inbounds [3000 x i8], [3000 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %8
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%10 = load i32, i32* @stdout
%11 = call i32 @fflush(i32 %10)
br label %12
12: ; preds = %1, %6
%13 = phi i32 [ %4, %6 ], [ -1, %1 ]
ret i32 %13
}