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

/* Variables and functions */
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, char, int);
scalar_t__ writeToClient(int, char *);
int sendFile(FILE *fp, int clientsd) {
  int buffSize = 256;
  int counter;
  char buff[buffSize + 1];
  int r;
  memset(buff, '\0', (buffSize + 1) * sizeof(char));
  r = buffSize;
  counter = 0;
  while (r == buffSize) {
    r = fread(buff, sizeof(char), buffSize, fp);
    counter += writeToClient(clientsd, buff);
    memset(buff, '\0', buffSize * sizeof(char));
  }
  return counter;
}


x86 assembly (clang, -O0):
<sendFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x100,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    11e8 <sendFile+0xb8>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <writeToClient@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
movslq -0x10(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
jmp    1191 <sendFile+0x61>
mov    -0x14(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x110,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rsp,%r12
xor    %ebp,%ebp
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x101,%edx
call   1040 <memset@plt>
nopl   0x0(%rax)
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %eax,%ebx
mov    %r14d,%edi
mov    %r12,%rsi
call   1050 <writeToClient@plt>
add    %eax,%ebp
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
cmp    $0x100,%ebx
je     1160 <sendFile+0x30>
mov    %ebp,%eax
add    $0x110,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sendFile(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 256, i32* %5
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %7
%14 = alloca i8, i64 %12
store i64 %12, i64* %8
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i32 @memset(i8* %14, i8 signext 0, i32 %19)
%21 = load i32, i32* %5
store i32 %21, i32* %9
store i32 0, i32* %6
br label %22
22: ; preds = %26, %2
%23 = load i32, i32* %9
%24 = load i32, i32* %5
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %41
26: ; preds = %22
%27 = load i32, i32* %5
%28 = load i32*, i32** %3
%29 = call i32 @fread(i8* %14, i32 1, i32 %27, i32* %28)
store i32 %29, i32* %9
%30 = load i32, i32* %4
%31 = call i64 @writeToClient(i32 %30, i8* %14)
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = add nsw i64 %33, %31
%35 = trunc i64 %34 to i32
store i32 %35, i32* %6
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = mul i64 %37, 1
%39 = trunc i64 %38 to i32
%40 = call i32 @memset(i8* %14, i8 signext 0, i32 %39)
br label %22
41: ; preds = %22
%42 = load i32, i32* %6
%43 = load i8*, i8** %7
ret i32 %42
}

LLVM IR (-O2):
define i32 @sendFile(i32* nocapture %0, i32 %1) {
%3 = alloca [257 x i8]
%4 = getelementptr inbounds [257 x i8], [257 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i8 signext 0, i32 257)
br label %6
6: ; preds = %2, %6
%7 = phi i32 [ 0, %2 ], [ %11, %6 ]
%8 = call i32 @fread(i8* %4, i32 1, i32 256, i32* %0)
%9 = call i64 @writeToClient(i32 %1, i8* %4)
%10 = trunc i64 %9 to i32
%11 = add i32 %7, %10
%12 = call i32 @memset(i8* %4, i8 signext 0, i32 256)
%13 = icmp eq i32 %8, 256
br i1 %13, label %6, label %14
14: ; preds = %6
ret i32 %11
}