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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ putcrlf(int, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void send_res(int conn, FILE *res) {
  size_t size;
  ssize_t len;
  char *res_line = NULL;
  while ((len = getline(&res_line, &size, res)) > 0) {
    res_line[len - 1] = '\0';
    putcrlf(conn, res_line);
  }
  free(res_line);
  if (!feof(res)) {
    fprintf(stderr, "read response failed: %s\n", strerror(errno));
    exit(1);
  }
}


x86 assembly (clang, -O0):
<send_res>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11c6 <send_res+0x56>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1060 <putcrlf@plt>
jmp    1187 <send_res+0x17>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
jne    1217 <send_res+0xa7>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xdf8(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_res>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rbx,%rdx
call   1070 <getline@plt>
test   %eax,%eax
jle    11da <send_res+0x6a>
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rcx
add    $0xffffffff,%eax
movb   $0x0,(%rcx,%rax,1)
mov    0x8(%rsp),%rsi
mov    %ebp,%edi
call   1060 <putcrlf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <getline@plt>
test   %eax,%eax
jg     11b0 <send_res+0x40>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     11fb <send_res+0x8b>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dde(%rip),%rax
mov    (%rax),%ebx
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xde7(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"read response failed: %s\0A\00"
@errno = global i32 0
define void @send_res(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
store i32* %1, i32** %4
store i8* null, i8** %7
br label %8
8: ; preds = %12, %2
%9 = load i32*, i32** %4
%10 = call i32 @getline(i8** %7, i64* %5, i32* %9)
store i32 %10, i32* %6
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = load i8*, i8** %7
%14 = load i32, i32* %6
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8 0, i8* %17
%18 = load i32, i32* %3
%19 = load i8*, i8** %7
%20 = call i32 @putcrlf(i32 %18, i8* %19)
br label %8
21: ; preds = %8
%22 = load i8*, i8** %7
%23 = call i32 @free(i8* %22)
%24 = load i32*, i32** %4
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %33, label %27
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %21
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"read response failed: %s\0A\00"
@errno = global i32 0
define void @send_res(i32 %0, i32* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = bitcast i64* %3 to i8*
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = call i32 @getline(i8** %4, i64* %3, i32* %1)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %2, %9
%10 = phi i32 [ %17, %9 ], [ %7, %2 ]
%11 = load i8*, i8** %4
%12 = add nsw i32 %10, -1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8 0, i8* %14
%15 = load i8*, i8** %4
%16 = call i32 @putcrlf(i32 %0, i8* %15)
%17 = call i32 @getline(i8** %4, i64* %3, i32* %1)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %9, label %19
19: ; preds = %9, %2
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
%22 = call i32 @feof(i32* %1)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %19
ret void
}