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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int http_header(int socket, char *header, int close_socket) {
  int r = -1;
  char buffer[1024 * 1024];
  sprintf(buffer, "%s\r\nContent-length: 0\r\n\r\n", header);
  int len = strlen(buffer);
  if (send(socket, buffer, len, 0) == len) {
    r = 0;
  }
  if (close_socket) {
    close(socket);
  }
  return r;
}


x86 assembly (clang, -O0):
<http_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100030,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
lea    -0x100020(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe92(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x100020(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x100024(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x100020(%rbp),%rsi
mov    -0x100024(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    -0x100024(%rbp),%eax
jne    11af <http_header+0x6f>
movl   $0x0,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c1 <http_header+0x81>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x100030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_header>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x100008,%rsp
mov    %edx,%r15d
mov    %rsi,%rdx
mov    %edi,%r14d
lea    0xea3(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,%ebx
test   %r15d,%r15d
je     1190 <http_header+0x50>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
cmp    %ebp,%ebx
setne  %al
neg    %eax
add    $0x100008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"%s\0D\0AContent-length: 0\0D\0A\0D\0A\00"
define i32 @http_header(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1048576 x i8]
%9 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 -1, i32* %7
%10 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %8, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %8, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %9
%15 = load i32, i32* %4
%16 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %8, i64 0, i64 0
%17 = load i32, i32* %9
%18 = call i32 @send(i32 %15, i8* %16, i32 %17, i32 0)
%19 = load i32, i32* %9
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %3
store i32 0, i32* %7
br label %22
22: ; preds = %21, %3
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %4
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* %7
ret i32 %29
}

LLVM IR (-O2):
@.str = [26 x i8] c"%s\0D\0AContent-length: 0\0D\0A\0D\0A\00"
define i32 @http_header(i32 %0, i8* %1, i32 %2) {
%4 = alloca [1048576 x i8]
%5 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = call i32 @strlen(i8* %5)
%8 = call i32 @send(i32 %0, i8* %5, i32 %7, i32 0)
%9 = icmp eq i32 %2, 0
br i1 %9, label %12, label %10
10: ; preds = %3
%11 = call i32 @close(i32 %0)
br label %12
12: ; preds = %10, %3
%13 = icmp ne i32 %8, %7
%14 = sext i1 %13 to i32
ret i32 %14
}