#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*/ bzero(char *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
scalar_t__ strcmp(char *, char *);
int recvMSG(int servsock) {
  int n = 0;
  char buffer[512];
  bzero(buffer, 512);
  n = read(servsock, buffer, 512);
  if (n < 0)
    error("ERROR reading from socket");
  if (strcmp(buffer, "quit") == 0)
    return 1;
  else {
    printf("%s\n", buffer);
    return 0;
  }
}


x86 assembly (clang, -O0):
<recvMSG>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x210(%rbp),%rdi
mov    $0x200,%esi
call   1070 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11a3 <recvMSG+0x53>
lea    0xe62(%rip),%rdi
call   1060 <error@plt>
lea    -0x210(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11cc <recvMSG+0x7c>
movl   $0x1,-0x4(%rbp)
jmp    11e6 <recvMSG+0x96>
lea    -0x210(%rbp),%rsi
lea    0xe45(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recvMSG>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x200,%esi
call   1070 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1040 <read@plt>
test   %eax,%eax
jns    118b <recvMSG+0x3b>
lea    0xe7a(%rip),%rdi
call   1060 <error@plt>
lea    0xe88(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11b2 <recvMSG+0x62>
lea    0xe79(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11b7 <recvMSG+0x67>
mov    $0x1,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [5 x i8] c"quit\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @recvMSG(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [512 x i8]
store i32 %0, i32* %3
store i32 0, i32* %4
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 512)
%8 = load i32, i32* %3
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 512)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%17 = call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15
store i32 1, i32* %2
br label %23
20: ; preds = %15
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %21)
store i32 0, i32* %2
br label %23
23: ; preds = %20, %19
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [26 x i8] c"ERROR reading from socket\00"
@.str.1 = [5 x i8] c"quit\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @recvMSG(i32 %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32 @bzero(i8* %3, i32 512)
%5 = call i32 @read(i32 %0, i8* %3, i32 512)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %14
14: ; preds = %9, %12
%15 = phi i32 [ 0, %12 ], [ 1, %9 ]
ret i32 %15
}