#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
size_t read(int, char *, int);
int /*<<< orphan*/ stdin;
size_t strlen(char *);
int /*<<< orphan*/ write(int, char *, size_t);
void client(int readfd, int writefd) {
  size_t len;
  ssize_t n;
  char buff[4096];
  printf("\n Please input the name of the file to be sent\n");
  fgets(buff, 4096, stdin);
  len = strlen(buff);
  if (buff[len - 1] == '\n')
    buff[len - 1] = '\0';
  write(writefd, buff, len);
  while ((n = read(readfd, buff, 4096)) > 0)
    write(1, buff, n);
}


x86 assembly (clang, -O0):
<client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    0xe98(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1020(%rbp),%rdi
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1070 <fgets@plt>
lea    -0x1020(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
movsbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    11c0 <client+0x70>
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
mov    -0x8(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jbe    120f <client+0xbf>
lea    -0x1020(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    11d3 <client+0x83>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<client>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %esi,%r14d
mov    %edi,%ebx
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x1000,%esi
call   1070 <fgets@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    1199 <client+0x49>
movb   $0x0,-0x1(%rsp,%rax,1)
mov    %rsp,%rbp
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %rax,%rax
je     11f4 <client+0xa4>
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1060 <read@plt>
test   %rax,%rax
jne    11d0 <client+0x80>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"\0A Please input the name of the file to be sent\0A\00"
@stdin = global i32 0
define void @client(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca [4096 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = call i32 @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %9, i32 4096, i32 %10)
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = sub i64 %14, 1
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i64, i64* %5
%22 = sub i64 %21, 1
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %20, %2
%25 = load i32, i32* %4
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%27 = load i64, i64* %5
%28 = call i32 @write(i32 %25, i8* %26, i64 %27)
br label %29
29: ; preds = %34, %24
%30 = load i32, i32* %3
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%32 = call i64 @read(i32 %30, i8* %31, i32 4096)
store i64 %32, i64* %6
%33 = icmp ugt i64 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%36 = load i64, i64* %6
%37 = call i32 @write(i32 1, i8* %35, i64 %36)
br label %29
38: ; preds = %29
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@str = [47 x i8] c"\0A Please input the name of the file to be sent\00"
define void @client(i32 %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 4096, i32 %6)
%8 = call i64 @strlen(i8* %4)
%9 = add i64 %8, -1
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %14
13: ; preds = %2
store i8 0, i8* %10
br label %14
14: ; preds = %13, %2
%15 = call i32 @write(i32 %1, i8* %4, i64 %8)
%16 = call i64 @read(i32 %0, i8* %4, i32 4096)
%17 = icmp eq i64 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %14, %18
%19 = phi i64 [ %21, %18 ], [ %16, %14 ]
%20 = call i32 @write(i32 1, i8* %4, i64 %19)
%21 = call i64 @read(i32 %0, i8* %4, i32 4096)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %18
23: ; preds = %18, %14
ret void
}