#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
char *gettext(char *);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
void send_recv(int i, int sockfd) {
  char send_buf[1024];
  char recv_buf[1024];
  int nbyte_recvd;
  if (i == 0) {
    fgets(send_buf, 1024, stdin);
    if (strcmp(send_buf, "quit\n") == 0) {
      exit(0);
    } else
      send(sockfd, send_buf, strlen(send_buf), 0);
  } else {
    nbyte_recvd = recv(sockfd, recv_buf, 1024, 0);
    recv_buf[nbyte_recvd] = '\0';
    printf(gettext("%s\n"), recv_buf);
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<send_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1227 <send_recv+0x97>
lea    -0x410(%rbp),%rdi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1080 <fgets@plt>
lea    -0x410(%rbp),%rdi
lea    0xe2d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    11e9 <send_recv+0x59>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x824(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x820(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x824(%rbp),%edi
mov    -0x820(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    127b <send_recv+0xeb>
mov    -0x8(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x814(%rbp)
movslq -0x814(%rbp),%rax
movb   $0x0,-0x810(%rbp,%rax,1)
lea    0xdad(%rip),%rdi
call   1050 <gettext@plt>
mov    %rax,%rdi
lea    -0x810(%rbp),%rsi
call   1070 <printf@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_recv>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebx
test   %edi,%edi
je     11e1 <send_recv+0x51>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xe45(%rip),%rdi
call   1050 <gettext@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   10a0 <fflush@plt>
jmp    1227 <send_recv+0x97>
mov    0x2e00(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
call   1080 <fgets@plt>
lea    0xdff(%rip),%rsi
mov    %r14,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1232 <send_recv+0xa2>
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [6 x i8] c"quit\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
define void @send_recv(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %26
10: ; preds = %2
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 1024, i32 %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %10
%20 = load i32, i32* %4
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @send(i32 %20, i8* %21, i32 %23, i32 0)
br label %25
25: ; preds = %19
br label %38
26: ; preds = %2
%27 = load i32, i32* %4
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%29 = call i32 @recv(i32 %27, i8* %28, i32 1024, i32 0)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %31
store i8 0, i8* %32
%33 = call i8* @gettext(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%35 = call i32 @printf(i8* %33, i8* %34)
%36 = load i32, i32* @stdout
%37 = call i32 @fflush(i32 %36)
br label %38
38: ; preds = %26, %25
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [6 x i8] c"quit\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@stdout = global i32 0
define void @send_recv(i32 %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 0
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %5, i32 1024, i32 %9)
%11 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = call i32 @exit(i32 0)
unreachable
15: ; preds = %8
%16 = call i32 @strlen(i8* %5)
%17 = call i32 @send(i32 %1, i8* %5, i32 %16, i32 0)
br label %26
18: ; preds = %2
%19 = call i32 @recv(i32 %1, i8* %6, i32 1024, i32 0)
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i8* @gettext(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @printf(i8* %22, i8* %6)
%24 = load i32, i32* @stdout
%25 = call i32 @fflush(i32 %24)
br label %26
26: ; preds = %18, %15
ret void
}