#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 ssize_t;
typedef int /*<<< orphan*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ find_and_replace(char *, int, char, char);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ send(int, char *, int, int);
void send_proc_file(int clientfd, char *path) {
  FILE *fp = fopen(path, "r");
  char buffer[100];
  ssize_t len;
  do {
    len = fread(buffer, 1, sizeof(buffer), fp);
    find_and_replace(buffer, len, '\0', '\n');
    send(clientfd, buffer, len, 1);
  } while (len == sizeof(buffer));
  fclose(fp);
}


x86 assembly (clang, -O0):
<send_proc_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x64,%edx
call   1030 <fread@plt>
mov    %eax,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x84(%rbp),%esi
xor    %edx,%edx
mov    $0xa,%ecx
call   1060 <find_and_replace@plt>
mov    -0x4(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0x84(%rbp),%edx
mov    $0x1,%ecx
call   1050 <send@plt>
movslq -0x84(%rbp),%rax
cmp    $0x64,%rax
je     1176 <send_proc_file+0x26>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_proc_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rax
mov    %edi,%r14d
lea    0xe99(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x64,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    $0xa,%ecx
call   1060 <find_and_replace@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
mov    $0x1,%ecx
call   1050 <send@plt>
cmp    $0x64,%ebx
je     1180 <send_proc_file+0x30>
mov    %r15,%rdi
call   1040 <fclose@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define void @send_proc_file(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [100 x i8]
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
br label %10
10: ; preds = %21, %2
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%12 = load i32*, i32** %5
%13 = call i32 @fread(i8* %11, i32 1, i32 100, i32* %12)
store i32 %13, i32* %7
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%15 = load i32, i32* %7
%16 = call i32 @find_and_replace(i8* %14, i32 %15, i8 signext 0, i8 signext 10)
%17 = load i32, i32* %3
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* %7
%20 = call i32 @send(i32 %17, i8* %18, i32 %19, i32 1)
br label %21
21: ; preds = %10
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = icmp eq i64 %23, 100
br i1 %24, label %10, label %25
25: ; preds = %21
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define void @send_proc_file(i32 %0, i8* nocapture %1) {
%3 = alloca [100 x i8]
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
br label %6
6: ; preds = %6, %2
%7 = call i32 @fread(i8* %5, i32 1, i32 100, i32* %4)
%8 = call i32 @find_and_replace(i8* %5, i32 %7, i8 signext 0, i8 signext 10)
%9 = call i32 @send(i32 %0, i8* %5, i32 %7, i32 1)
%10 = icmp eq i32 %7, 100
br i1 %10, label %6, label %11
11: ; preds = %6
%12 = call i32 @fclose(i32* %4)
ret void
}