#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 */
struct ns_connection {
  int dummy;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ ns_send(struct ns_connection *, char *, size_t);
void send_file_data(struct ns_connection *nc, FILE *fp) {
  char buf[BUFSIZ];
  size_t n;
  while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
    ns_send(nc, buf, n);
  }
}


x86 assembly (clang, -O0):
<send_file_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    %eax,%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jbe    119c <send_file_data+0x7c>
mov    -0x30(%rbp),%rsi
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
call   1040 <ns_send@plt>
jmp    1160 <send_file_data+0x40>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_file_data>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2ea8(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%rbx
mov    %r12,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
nop
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     1178 <send_file_data+0x58>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1040 <ns_send@plt>
jmp    1150 <send_file_data+0x30>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ns_connection = type { i32 }
@BUFSIZ = global i32 0
define void @send_file_data(%struct.ns_connection* %0, i32* %1) {
%3 = alloca %struct.ns_connection*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store %struct.ns_connection* %0, %struct.ns_connection** %3
store i32* %1, i32** %4
%8 = load i32, i32* @BUFSIZ
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
br label %12
12: ; preds = %17, %2
%13 = trunc i64 %9 to i32
%14 = load i32*, i32** %4
%15 = call i64 @fread(i8* %11, i32 1, i32 %13, i32* %14)
store i64 %15, i64* %7
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load %struct.ns_connection*, %struct.ns_connection** %3
%19 = load i64, i64* %7
%20 = call i32 @ns_send(%struct.ns_connection* %18, i8* %11, i64 %19)
br label %12
21: ; preds = %12
%22 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
%struct.ns_connection = type { i32 }
@BUFSIZ = global i32 0
define void @send_file_data(%struct.ns_connection* %0, i32* nocapture %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i64 @fread(i8* %5, i32 1, i32 %3, i32* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %13, label %8
8: ; preds = %2, %8
%9 = phi i64 [ %11, %8 ], [ %6, %2 ]
%10 = call i32 @ns_send(%struct.ns_connection* %0, i8* %5, i64 %9)
%11 = call i64 @fread(i8* %5, i32 1, i32 %3, i32* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %8
13: ; preds = %8, %2
ret void
}