#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 /*<<< orphan*/ err_abort(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ generate_okHeader(char const *, char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ send_error(int, char const *, int, char *);
scalar_t__ strlen(char *);
int write(int, char *, int);
void send_html(int sockfd, const char *path, const char *version) {
  FILE *file = fopen(path, "r");
  if (file == NULL) {
    send_error(sockfd, version, 404, "Not Found");
    return;
  }
  char response[255 + 1];
  memset(response, '\0', 255 + 1);
  generate_okHeader(path, response);
  int n;
  for (int i = 0;; i++) {
    int resLength = (int)strlen(response);
    if (resLength > 0) {
      printf("\nsprintf\n");
      n = resLength;
    } else {
      printf("\nSPRINTF\n");
      n = fread(response, 1, 255, file);
    }
    printf("response (i: %d l: %d):\n%s\n\n", i, n, response);
    if (write(sockfd, response, n) != n) {
      err_abort("Fehler beim Schreiben des Sockets!");
    }
    if (n < 255 && resLength == 0) {
      printf("HTML-Transfer vollendet!\n");
      break;
    }
    memset(response, '\0', 255 + 1);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<send_html>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f2 <send_html+0x52>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x194,%edx
lea    0xe1a(%rip),%rcx
call   10a0 <send_error@plt>
jmp    1339 <send_html+0x199>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1090 <generate_okHeader@plt>
movl   $0x0,-0x128(%rbp)
lea    -0x120(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x12c(%rbp)
cmpl   $0x0,-0x12c(%rbp)
jle    125d <send_html+0xbd>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x12c(%rbp),%eax
mov    %eax,-0x124(%rbp)
jmp    128b <send_html+0xeb>
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0xff,%edx
call   1030 <fread@plt>
mov    %eax,-0x124(%rbp)
mov    -0x128(%rbp),%esi
mov    -0x124(%rbp),%edx
lea    -0x120(%rbp),%rcx
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    -0x124(%rbp),%edx
call   1040 <write@plt>
cmp    -0x124(%rbp),%eax
je     12d9 <send_html+0x139>
lea    0xd69(%rip),%rdi
call   10b0 <err_abort@plt>
cmpl   $0xff,-0x124(%rbp)
jge    1309 <send_html+0x169>
cmpl   $0x0,-0x12c(%rbp)
jne    1309 <send_html+0x169>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1330 <send_html+0x190>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1080 <memset@plt>
mov    -0x128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x128(%rbp)
jmp    121f <send_html+0x7f>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_html>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe30(%rip),%rsi
mov    %r14,%rdi
call   10d0 <fopen@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1312 <send_html+0x162>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10a0 <generate_okHeader@plt>
lea    0xe00(%rip),%r12
xor    %r13d,%r13d
jmp    1233 <send_html+0x83>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1090 <memset@plt>
add    $0x1,%r13d
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %rax,%r15
test   %r15d,%r15d
jle    1260 <send_html+0xb0>
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%r14d
jmp    1286 <send_html+0xd6>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0xde5(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0xff,%edx
mov    0x8(%rsp),%rcx
call   1040 <fread@plt>
mov    %eax,%r14d
mov    %r12,%rdi
mov    %r13d,%esi
mov    %r14d,%edx
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1050 <write@plt>
cmp    %r14d,%eax
jne    12d0 <send_html+0x120>
cmp    $0xfe,%r14d
jg     1220 <send_html+0x70>
test   %r15d,%r15d
jne    1220 <send_html+0x70>
jmp    12ea <send_html+0x13a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xd52(%rip),%rdi
call   10c0 <err_abort@plt>
cmp    $0xfe,%r14d
jle    12b8 <send_html+0x108>
jmp    1220 <send_html+0x70>
lea    0xd64(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rdi
call   1060 <fclose@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xce9(%rip),%rcx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x194,%edx
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <send_error@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"Not Found\00"
@.str.2 = [10 x i8] c"\0Asprintf\0A\00"
@.str.3 = [10 x i8] c"\0ASPRINTF\0A\00"
@.str.4 = [29 x i8] c"response (i: %d l: %d):\0A%s\0A\0A\00"
@.str.5 = [35 x i8] c"Fehler beim Schreiben des Sockets!\00"
@.str.6 = [26 x i8] c"HTML-Transfer vollendet!\0A\00"
define void @send_html(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i32, i32* %4
%18 = load i8*, i8** %6
%19 = call i32 @send_error(i32 %17, i8* %18, i32 404, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %70
20: ; preds = %3
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i8 signext 0, i32 256)
%23 = load i8*, i8** %5
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%25 = call i32 @generate_okHeader(i8* %23, i8* %24)
store i32 0, i32* %10
br label %26
26: ; preds = %64, %20
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = call i64 @strlen(i8* %27)
%29 = trunc i64 %28 to i32
store i32 %29, i32* %11
%30 = load i32, i32* %11
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* %11
store i32 %34, i32* %9
br label %40
35: ; preds = %26
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%38 = load i32*, i32** %7
%39 = call i32 @fread(i8* %37, i32 1, i32 255, i32* %38)
store i32 %39, i32* %9
br label %40
40: ; preds = %35, %32
%41 = load i32, i32* %10
%42 = load i32, i32* %9
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %41, i32 %42, i8* %43)
%45 = load i32, i32* %4
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%47 = load i32, i32* %9
%48 = call i32 @write(i32 %45, i8* %46, i32 %47)
%49 = load i32, i32* %9
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %53
51: ; preds = %40
%52 = call i32 @err_abort(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %53
53: ; preds = %51, %40
%54 = load i32, i32* %9
%55 = icmp slt i32 %54, 255
br i1 %55, label %56, label %61
56: ; preds = %53
%57 = load i32, i32* %11
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %67
61: ; preds = %56, %53
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%63 = call i32 @memset(i8* %62, i8 signext 0, i32 256)
br label %64
64: ; preds = %61
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %26
67: ; preds = %59
%68 = load i32*, i32** %7
%69 = call i32 @fclose(i32* %68)
br label %70
70: ; preds = %67, %16
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [10 x i8] c"Not Found\00"
@.str.4 = [29 x i8] c"response (i: %d l: %d):\0A%s\0A\0A\00"
@.str.5 = [35 x i8] c"Fehler beim Schreiben des Sockets!\00"
@str = [9 x i8] c"\0ASPRINTF\00"
@str.7 = [25 x i8] c"HTML-Transfer vollendet!\00"
@str.8 = [9 x i8] c"\0Asprintf\00"
define void @send_html(i32 %0, i8* %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @send_error(i32 %0, i8* %2, i32 404, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
br label %40
9: ; preds = %3
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i8 signext 0, i32 256)
%12 = call i32 @generate_okHeader(i8* %1, i8* %10)
br label %13
13: ; preds = %34, %9
%14 = phi i32 [ 0, %9 ], [ %36, %34 ]
%15 = call i64 @strlen(i8* %10)
%16 = trunc i64 %15 to i32
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.8, i64 0, i64 0))
br label %23
20: ; preds = %13
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%22 = call i32 @fread(i8* %10, i32 1, i32 255, i32* %5)
br label %23
23: ; preds = %20, %18
%24 = phi i32 [ %16, %18 ], [ %22, %20 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i32 %14, i32 %24, i8* %10)
%26 = call i32 @write(i32 %0, i8* %10, i32 %24)
%27 = icmp eq i32 %26, %24
br i1 %27, label %30, label %28
28: ; preds = %23
%29 = call i32 @err_abort(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %30
30: ; preds = %28, %23
%31 = icmp slt i32 %24, 255
%32 = icmp eq i32 %16, 0
%33 = select i1 %31, i1 %32, i1 false
br i1 %33, label %37, label %34
34: ; preds = %30
%35 = call i32 @memset(i8* %10, i8 signext 0, i32 256)
%36 = add nuw nsw i32 %14, 1
br label %13
37: ; preds = %30
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%39 = call i32 @fclose(i32* %5)
br label %40
40: ; preds = %37, %7
ret void
}