#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int fprintf(int /*<<< orphan*/ *, char *, ...);
int http_reply(int fd, FILE **fpp, int code, char *msg, char *type,
               char *content) {
  FILE *fp = fdopen(fd, "w");
  int bytes = 0;
  if (fp != NULL) {
    bytes = fprintf(fp, "HTTP/1.0 %d %s\r\n", code, msg);
    bytes += fprintf(fp, "Content-type: %s\r\n\r\n", type);
    if (content)
      bytes += fprintf(fp, "%s\r\n", content);
  }
  fflush(fp);
  if (fpp)
    *fpp = fp;
  else
    fclose(fp);
  return bytes;
}


x86 assembly (clang, -O0):
<http_reply>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x4(%rbp),%edi
lea    0xe98(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11e7 <http_reply+0xa7>
mov    -0x38(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11e2 <http_reply+0xa2>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
add    -0x3c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
jmp    11e7 <http_reply+0xa7>
mov    -0x38(%rbp),%rdi
call   1050 <fflush@plt>
cmpq   $0x0,-0x10(%rbp)
je     120b <http_reply+0xcb>
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    1214 <http_reply+0xd4>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x3c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_reply>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8,%r12
mov    %rcx,%r13
mov    %edx,%ebp
mov    %rsi,%r14
lea    0xea0(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11bc <http_reply+0x7c>
lea    0xe8e(%rip),%rsi
mov    %rbx,%rdi
mov    %ebp,%edx
mov    %r13,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %eax,%r13d
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %eax,%ebp
add    %r13d,%ebp
test   %r15,%r15
je     11be <http_reply+0x7e>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
add    %eax,%ebp
jmp    11be <http_reply+0x7e>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1050 <fflush@plt>
test   %r14,%r14
je     11d0 <http_reply+0x90>
mov    %rbx,(%r14)
jmp    11d8 <http_reply+0x98>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [17 x i8] c"HTTP/1.0 %d %s\0D\0A\00"
@.str.2 = [21 x i8] c"Content-type: %s\0D\0A\0D\0A\00"
@.str.3 = [5 x i8] c"%s\0D\0A\00"
define i32 @http_reply(i32 %0, i32** %1, i32 %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32**
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
store i32 %0, i32* %7
store i32** %1, i32*** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%15 = load i32, i32* %7
%16 = call i32* @fdopen(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %13
store i32 0, i32* %14
%17 = load i32*, i32** %13
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %38
19: ; preds = %6
%20 = load i32*, i32** %13
%21 = load i32, i32* %9
%22 = load i8*, i8** %10
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %21, i8* %22)
store i32 %23, i32* %14
%24 = load i32*, i32** %13
%25 = load i8*, i8** %11
%26 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %14
%28 = add nsw i32 %27, %26
store i32 %28, i32* %14
%29 = load i8*, i8** %12
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %37
31: ; preds = %19
%32 = load i32*, i32** %13
%33 = load i8*, i8** %12
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %14
%36 = add nsw i32 %35, %34
store i32 %36, i32* %14
br label %37
37: ; preds = %31, %19
br label %38
38: ; preds = %37, %6
%39 = load i32*, i32** %13
%40 = call i32 @fflush(i32* %39)
%41 = load i32**, i32*** %8
%42 = icmp ne i32** %41, null
br i1 %42, label %43, label %46
43: ; preds = %38
%44 = load i32*, i32** %13
%45 = load i32**, i32*** %8
store i32* %44, i32** %45
br label %49
46: ; preds = %38
%47 = load i32*, i32** %13
%48 = call i32 @fclose(i32* %47)
br label %49
49: ; preds = %46, %43
%50 = load i32, i32* %14
ret i32 %50
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [17 x i8] c"HTTP/1.0 %d %s\0D\0A\00"
@.str.2 = [21 x i8] c"Content-type: %s\0D\0A\0D\0A\00"
@.str.3 = [5 x i8] c"%s\0D\0A\00"
define i32 @http_reply(i32 %0, i32** writeonly %1, i32 %2, i8* %3, i8* %4, i8* %5) {
%7 = tail call i32* @fdopen(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %17, label %9
9: ; preds = %6
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %2, i8* %3)
%11 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%12 = add nsw i32 %11, %10
%13 = icmp eq i8* %5, null
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%16 = add nsw i32 %15, %12
br label %17
17: ; preds = %9, %14, %6
%18 = phi i32 [ %16, %14 ], [ %12, %9 ], [ 0, %6 ]
%19 = tail call i32 @fflush(i32* %7)
%20 = icmp eq i32** %1, null
br i1 %20, label %22, label %21
21: ; preds = %17
store i32* %7, i32** %1
br label %24
22: ; preds = %17
%23 = tail call i32 @fclose(i32* %7)
br label %24
24: ; preds = %22, %21
ret i32 %18
}