#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*/ buff;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void func(int sockfd) {
  char buff[80];
  int n;
  for (;;) {
    bzero(buff, 80);
    read(sockfd, buff, sizeof(buff));
    printf("From client: %s\t To client : ", buff);
    bzero(buff, 80);
    n = 0;
    while ((buff[n++] = getchar()) != '\n')
      ;
    write(sockfd, buff, sizeof(buff));
    if (strncmp("exit", buff, 4) == 0) {
      printf("Server Exit...\n");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
mov    $0x50,%esi
call   1080 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x50,%edx
call   1060 <read@plt>
lea    -0x60(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rdi
mov    $0x50,%esi
call   1080 <bzero@plt>
movl   $0x0,-0x64(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x64(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x64(%rbp)
movslq %ecx,%rcx
mov    %al,-0x60(%rbp,%rcx,1)
movsbl %al,%eax
cmp    $0xa,%eax
je     11db <func+0x7b>
jmp    11b1 <func+0x51>
mov    -0x4(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x50,%edx
call   1040 <write@plt>
lea    -0x60(%rbp),%rsi
lea    0xe27(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    121e <func+0xbe>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1223 <func+0xc3>
jmp    116b <func+0xb>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<func>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
mov    %edi,%r12d
mov    %rsp,%rbp
lea    0xe77(%rip),%r14
lea    0xe8e(%rip),%r15
mov    %rbp,%rdi
mov    $0x50,%esi
call   1090 <bzero@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x50,%edx
call   1070 <read@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
mov    $0x50,%esi
call   1090 <bzero@plt>
mov    %rbp,%rbx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
cmp    $0xa,%al
jne    11d0 <func+0x60>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x50,%edx
call   1050 <write@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1190 <func+0x20>
lea    0xe16(%rip),%rdi
call   1040 <puts@plt>
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"From client: %s\09 To client : \00"
@.str.1 = [5 x i8] c"exit\00"
@.str.2 = [16 x i8] c"Server Exit...\0A\00"
define void @func(i32 %0) {
%2 = alloca i32
%3 = alloca [80 x i8]
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %33, %1
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%7 = call i32 @bzero(i8* %6, i32 80)
%8 = load i32, i32* %2
%9 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 80)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%14 = call i32 @bzero(i8* %13, i32 80)
store i32 0, i32* %4
br label %15
15: ; preds = %23, %5
%16 = call signext i8 (...) @getchar()
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %19
store i8 %16, i8* %20
%21 = sext i8 %16 to i32
%22 = icmp ne i32 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %15
br label %15
24: ; preds = %15
%25 = load i32, i32* %2
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%27 = call i32 @write(i32 %25, i8* %26, i32 80)
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%29 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %28, i32 4)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %34
33: ; preds = %24
br label %5
34: ; preds = %31
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"From client: %s\09 To client : \00"
@.str.1 = [5 x i8] c"exit\00"
@str = [15 x i8] c"Server Exit...\00"
define void @func(i32 %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %15, %1
%5 = call i32 @bzero(i8* %3, i32 80)
%6 = call i32 @read(i32 %0, i8* %3, i32 80)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %3)
%8 = call i32 @bzero(i8* %3, i32 80)
br label %9
9: ; preds = %9, %4
%10 = phi i64 [ %12, %9 ], [ 0, %4 ]
%11 = call signext i8 (...) @getchar()
%12 = add nuw i64 %10, 1
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 %10
store i8 %11, i8* %13
%14 = icmp eq i8 %11, 10
br i1 %14, label %15, label %9
15: ; preds = %9
%16 = call i32 @write(i32 %0, i8* %3, i32 80)
%17 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %4
19: ; preds = %15
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
ret void
}