#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*/ buf2;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int strlen(char *);
int write(int, char *, int);
int http_nak(int fd, int code, const char *nak) {
  int len, len2;
  char buf[1024], buf2[1024];
  memset(buf, '\0', sizeof(buf));
  memset(buf2, '\0', sizeof(buf2));
  snprintf(buf2, sizeof(buf2),
           "<!DOCTYPE html PUBLIC \"-//IEIF//DTD HTML 2.0//EN\">\n"
           "<html><head><title>Error %d</title>\n"
           "</head><body>\n"
           "<h2>Error %d</h2>"
           "<h2>Helight Server: %s</h2>"
           "</body></html>\r\n",
           code, code, nak);
  len2 = strlen(buf2);
  snprintf(
      buf, sizeof(buf),
      "HTTP/1.1 %s\r\nServer: Helight\r\n%s\r\nContent-Length: %ld\r\n\r\n",
      nak, "Content-Type: text/html", (long)len2);
  len = strlen(buf);
  if (len != write(fd, buf, len)) {
    printf("writer head error: %s\n", nak);
    return -1;
  }
  if (len2 != write(fd, buf2, len2)) {
    printf("writer body  error: %s\n", nak);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<http_nak>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x820(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    -0xc(%rbp),%r8d
mov    -0x18(%rbp),%r9
mov    $0x400,%esi
lea    0xe57(%rip),%rdx
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%r9
mov    $0x400,%esi
lea    0xec8(%rip),%rdx
lea    0xefb(%rip),%r8
mov    $0x0,%al
call   1060 <snprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x824(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    -0x824(%rbp),%eax
cmp    %ecx,%eax
je     123e <http_nak+0xee>
mov    -0x18(%rbp),%rsi
lea    0xec7(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <http_nak+0x13c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x828(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    -0x828(%rbp),%eax
cmp    %ecx,%eax
je     1285 <http_nak+0x135>
mov    -0x18(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <http_nak+0x13c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_nak>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rdx,%r13
mov    %esi,%ebp
mov    %edi,%r15d
lea    0x400(%rsp),%r12
xor    %r14d,%r14d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    0xe64(%rip),%rdx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %ebp,%ecx
mov    %ebp,%r8d
mov    %r13,%r9
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
movslq %eax,%r9
lea    0xedb(%rip),%rdx
lea    0xf0e(%rip),%r8
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r13,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r15d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %eax,%ebx
jne    1215 <http_nak+0xc5>
mov    %rsp,%rsi
mov    %r15d,%edi
mov    %ebp,%edx
call   1030 <write@plt>
cmp    %eax,%ebp
je     122a <http_nak+0xda>
lea    0xef8(%rip),%rdi
jmp    121c <http_nak+0xcc>
lea    0xed8(%rip),%rdi
mov    %r13,%rsi
call   1050 <printf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [162 x i8] c"<!DOCTYPE html PUBLIC \22-//IEIF//DTD HTML 2.0//EN\22>\0A<html><head><title>Error %d</title>\0A</head><body>\0A<h2>Error %d</h2><h2>Helight Server: %s</h2></body></html>\0D\0A\00"
@.str.1 = [58 x i8] c"HTTP/1.1 %s\0D\0AServer: Helight\0D\0A%s\0D\0AContent-Length: %ld\0D\0A\0D\0A\00"
@.str.2 = [24 x i8] c"Content-Type: text/html\00"
@.str.3 = [23 x i8] c"writer head error: %s\0A\00"
@.str.4 = [24 x i8] c"writer body error: %s\0A\00"
define i32 @http_nak(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca [1024 x i8]
%11 = alloca [1024 x i8]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i8 signext 0, i32 1024)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i8 signext 0, i32 1024)
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%17 = load i32, i32* %6
%18 = load i32, i32* %6
%19 = load i8*, i8** %7
%20 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %16, i32 1024, i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18, i8* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %9
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%24 = load i8*, i8** %7
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %23, i32 1024, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %24, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 %26)
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = load i32, i32* %5
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%33 = load i32, i32* %8
%34 = call i32 @write(i32 %31, i8* %32, i32 %33)
%35 = icmp ne i32 %30, %34
br i1 %35, label %36, label %39
36: ; preds = %3
%37 = load i8*, i8** %7
%38 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %37)
store i32 -1, i32* %4
br label %50
39: ; preds = %3
%40 = load i32, i32* %9
%41 = load i32, i32* %5
%42 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%43 = load i32, i32* %9
%44 = call i32 @write(i32 %41, i8* %42, i32 %43)
%45 = icmp ne i32 %40, %44
br i1 %45, label %46, label %49
46: ; preds = %39
%47 = load i8*, i8** %7
%48 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %47)
store i32 -1, i32* %4
br label %50
49: ; preds = %39
store i32 0, i32* %4
br label %50
50: ; preds = %49, %46, %36
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@.str = [162 x i8] c"<!DOCTYPE html PUBLIC \22-//IEIF//DTD HTML 2.0//EN\22>\0A<html><head><title>Error %d</title>\0A</head><body>\0A<h2>Error %d</h2><h2>Helight Server: %s</h2></body></html>\0D\0A\00"
@.str.1 = [58 x i8] c"HTTP/1.1 %s\0D\0AServer: Helight\0D\0A%s\0D\0AContent-Length: %ld\0D\0A\0D\0A\00"
@.str.2 = [24 x i8] c"Content-Type: text/html\00"
@.str.3 = [23 x i8] c"writer head error: %s\0A\00"
@.str.4 = [24 x i8] c"writer body error: %s\0A\00"
define i32 @http_nak(i32 %0, i32 %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = call i32 @memset(i8* %6, i8 signext 0, i32 1024)
%9 = call i32 @memset(i8* %7, i8 signext 0, i32 1024)
%10 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %7, i32 1024, i8* getelementptr inbounds ([162 x i8], [162 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %1, i8* %2)
%11 = call i32 @strlen(i8* %7)
%12 = sext i32 %11 to i64
%13 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %6, i32 1024, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 %12)
%14 = call i32 @strlen(i8* %6)
%15 = call i32 @write(i32 %0, i8* %6, i32 %14)
%16 = icmp eq i32 %14, %15
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = call i32 @write(i32 %0, i8* %7, i32 %11)
%19 = icmp eq i32 %11, %18
br i1 %19, label %23, label %20
20: ; preds = %17, %3
%21 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %3 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), %17 ]
%22 = call i32 @printf(i8* %21, i8* %2)
br label %23
23: ; preds = %20, %17
%24 = phi i32 [ 0, %17 ], [ -1, %20 ]
ret i32 %24
}