#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
size_t read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strerror(int /*<<< orphan*/);
size_t strlen(char *);
size_t write(int, char *, size_t);
void str_cli(int sockfd) {
  char recvbuf[100], sendbuf[100];
  ssize_t n;
  while (1) {
    printf("\n(client) >>> ");
    if (fgets(sendbuf, 100, stdin) == NULL)
      break;
    n = write(sockfd, sendbuf, strlen(sendbuf));
    if (n != strlen(sendbuf)) {
      fprintf(stderr, "str_cli() - write() failed: %s\n", strerror(errno));
      break;
    }
    n = read(sockfd, recvbuf, 100);
    recvbuf[n] = '\0';
    if (n == 0) {
      fprintf(stderr, "str_cli() - read() end: server terminated.\n");
      break;
    } else if (n > 0) {
      printf("(server) >>> ");
      fputs(recvbuf, stdout);
    }
  }
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe6b(%rip),%rdi
call   1050 <printf@plt>
lea    -0xe0(%rbp),%rdi
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
jne    11c3 <str_cli+0x43>
jmp    12ec <str_cli+0x16c>
mov    -0x4(%rbp),%eax
mov    %eax,-0xfc(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0xf8(%rbp)
lea    -0xe0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xfc(%rbp),%edi
mov    -0xf8(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rax
mov    %rax,-0xf0(%rbp)
lea    -0xe0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0xf0(%rbp),%rax
cmp    %rcx,%rax
je     1268 <str_cli+0xe8>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x100(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x100(%rbp),%edi
mov    %rax,%rdx
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    12ec <str_cli+0x16c>
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
call   1070 <read@plt>
mov    %rax,-0xe8(%rbp)
mov    -0xe8(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
cmpq   $0x0,-0xe8(%rbp)
jne    12b6 <str_cli+0x136>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    12ec <str_cli+0x16c>
cmpq   $0x0,-0xe8(%rbp)
jbe    12e2 <str_cli+0x162>
lea    0xd90(%rip),%rdi
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2ced(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
jmp    12e7 <str_cli+0x167>
jmp    118e <str_cli+0xe>
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %edi,%r13d
lea    0xe65(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1080 <fgets@plt>
test   %rax,%rax
je     129f <str_cli+0x11f>
mov    %rsp,%rbx
lea    0x70(%rsp),%r14
mov    0x2dfa(%rip),%r15
lea    0xe2b(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbp
jne    125c <str_cli+0xdc>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1070 <read@plt>
movb   $0x0,0x70(%rsp,%rax,1)
test   %rax,%rax
je     1288 <str_cli+0x108>
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1060 <fputs@plt>
mov    %r12,%rdi
call   1050 <printf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1080 <fgets@plt>
test   %rax,%rax
jne    11e0 <str_cli+0x60>
jmp    129f <str_cli+0x11f>
mov    0x2d75(%rip),%rax
mov    (%rax),%ebx
mov    0x2d64(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd95(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    129f <str_cli+0x11f>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"\0A(client) >>> \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"str_cli() - write() failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [44 x i8] c"str_cli() - read() end: server terminated.\0A\00"
@.str.3 = [14 x i8] c"(server) >>> \00"
@stdout = global i32 0
define void @str_cli(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca i64
store i32 %0, i32* %2
br label %6
6: ; preds = %1, %48
%7 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32* @fgets(i8* %8, i32 100, i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %6
br label %49
13: ; preds = %6
%14 = load i32, i32* %2
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = call i64 @write(i32 %14, i8* %15, i64 %17)
store i64 %18, i64* %5
%19 = load i64, i64* %5
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%21 = call i64 @strlen(i8* %20)
%22 = icmp ne i64 %19, %21
br i1 %22, label %23, label %28
23: ; preds = %13
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i8* @strerror(i32 %25)
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %26)
br label %49
28: ; preds = %13
%29 = load i32, i32* %2
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%31 = call i64 @read(i32 %29, i8* %30, i32 100)
store i64 %31, i64* %5
%32 = load i64, i64* %5
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %32
store i8 0, i8* %33
%34 = load i64, i64* %5
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %49
39: ; preds = %28
%40 = load i64, i64* %5
%41 = icmp ugt i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%45 = load i32, i32* @stdout
%46 = call i32 @fputs(i8* %44, i32 %45)
br label %47
47: ; preds = %42, %39
br label %48
48: ; preds = %47
br label %6
49: ; preds = %36, %23, %12
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"\0A(client) >>> \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"str_cli() - write() failed: %s\0A\00"
@errno = global i32 0
@.str.2 = [44 x i8] c"str_cli() - read() end: server terminated.\0A\00"
@.str.3 = [14 x i8] c"(server) >>> \00"
@stdout = global i32 0
define void @str_cli(i32 %0) {
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %5, i32 100, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %35, label %10
10: ; preds = %1, %27
%11 = call i64 @strlen(i8* %5)
%12 = call i64 @write(i32 %0, i8* %5, i64 %11)
%13 = call i64 @strlen(i8* %5)
%14 = icmp eq i64 %12, %13
br i1 %14, label %20, label %15
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %35
20: ; preds = %10
%21 = call i64 @read(i32 %0, i8* %4, i32 100)
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %21
store i8 0, i8* %22
%23 = icmp eq i64 %21, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
br label %35
27: ; preds = %20
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* @stdout
%30 = call i32 @fputs(i8* %4, i32 %29)
%31 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%32 = load i32, i32* @stdin
%33 = call i32* @fgets(i8* %5, i32 100, i32 %32)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %10
35: ; preds = %27, %1, %24, %15
ret void
}