#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*/ err_dump(char *);
int /*<<< orphan*/ err_sys(char *);
scalar_t__ ferror(int *);
int /*<<< orphan*/ *fgets(char *, int, int *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int readline(int, char *, int);
int /*<<< orphan*/ stdout;
int strlen(char *);
int writen(int, char *, int);
str_cli(int *fd, int sockfd) {
  int n;
  char sendline[512], recvline[512];
  while (fgets(sendline, 512, fd) != NULL) {
    n = strlen(sendline);
    if (writen(sockfd, sendline, n) != n)
      err_sys("str_cli : writen error on socket");
    n = readline(sockfd, recvline, 512);
    if (n < 0)
      err_dump("str_cli: readline error");
    recvline[n] = 0;
    fputs(recvline, stdout);
  }
  if (ferror(fd))
    err_sys("str_cli: error reading file");
}


x86 assembly (clang, -O0):
<str_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     123a <str_cli+0xba>
lea    -0x220(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10a0 <writen@plt>
cmp    -0x18(%rbp),%eax
je     11e7 <str_cli+0x67>
lea    0xe1e(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
call   1070 <readline@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1214 <str_cli+0x94>
lea    0xe12(%rip),%rdi
call   1090 <err_dump@plt>
movslq -0x18(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rdi
mov    0x2db2(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
jmp    1192 <str_cli+0x12>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1259 <str_cli+0xd9>
lea    0xde5(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_cli>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebp
mov    %rdi,%r14
lea    0x200(%rsp),%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     124e <str_cli+0xce>
lea    0x200(%rsp),%r13
mov    %rsp,%r15
jmp    1213 <str_cli+0x93>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x200,%edx
call   1070 <readline@plt>
mov    %eax,%r12d
test   %eax,%eax
js     1240 <str_cli+0xc0>
movslq %r12d,%rax
movb   $0x0,(%rsp,%rax,1)
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1060 <fputs@plt>
mov    %r13,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     124e <str_cli+0xce>
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %ebp,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   10a0 <writen@plt>
cmp    %ebx,%eax
je     11d0 <str_cli+0x50>
lea    0xdcc(%rip),%rdi
call   1040 <err_sys@plt>
jmp    11d0 <str_cli+0x50>
nopl   0x0(%rax,%rax,1)
lea    0xdda(%rip),%rdi
call   1090 <err_dump@plt>
jmp    11e6 <str_cli+0x66>
mov    %r14,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1267 <str_cli+0xe7>
lea    0xdd7(%rip),%rdi
call   1040 <err_sys@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"str_cli : writen error on socket\00"
@.str.1 = [24 x i8] c"str_cli: readline error\00"
@stdout = global i32 0
@.str.2 = [28 x i8] c"str_cli: error reading file\00"
define i32 @str_cli(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [512 x i8]
%8 = alloca [512 x i8]
store i32* %0, i32** %4
store i32 %1, i32* %5
br label %9
9: ; preds = %33, %2
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%11 = load i32*, i32** %4
%12 = call i32* @fgets(i8* %10, i32 512, i32* %11)
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %40
14: ; preds = %9
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %5
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%19 = load i32, i32* %6
%20 = call i32 @writen(i32 %17, i8* %18, i32 %19)
%21 = load i32, i32* %6
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %14
%24 = call i32 @err_sys(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %14
%26 = load i32, i32* %5
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%28 = call i32 @readline(i32 %26, i8* %27, i32 512)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = call i32 @err_dump(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %25
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %35
store i8 0, i8* %36
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%38 = load i32, i32* @stdout
%39 = call i32 @fputs(i8* %37, i32 %38)
br label %9
40: ; preds = %9
%41 = load i32*, i32** %4
%42 = call i64 @ferror(i32* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @err_sys(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %40
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [33 x i8] c"str_cli : writen error on socket\00"
@.str.1 = [24 x i8] c"str_cli: readline error\00"
@stdout = global i32 0
@.str.2 = [28 x i8] c"str_cli: error reading file\00"
define i32 @str_cli(i32* nocapture %0, i32 %1) {
%3 = alloca [512 x i8]
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%7 = call i32* @fgets(i8* %5, i32 512, i32* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %27, label %9
9: ; preds = %2, %20
%10 = call i32 @strlen(i8* %5)
%11 = call i32 @writen(i32 %1, i8* %5, i32 %10)
%12 = icmp eq i32 %11, %10
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 @err_sys(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = call i32 @readline(i32 %1, i8* %6, i32 512)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @err_dump(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = sext i32 %16 to i64
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %21
store i8 0, i8* %22
%23 = load i32, i32* @stdout
%24 = call i32 @fputs(i8* %6, i32 %23)
%25 = call i32* @fgets(i8* %5, i32 512, i32* %0)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %9
27: ; preds = %20, %2
%28 = call i64 @ferror(i32* %0)
%29 = icmp eq i64 %28, 0
br i1 %29, label %32, label %30
30: ; preds = %27
%31 = call i32 @err_sys(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
ret i32 undef
}