#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 /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void closefd(int clientfd, char *input, int success) {
  char send[1024];
  sprintf(send, "HTTP/1.1 200 OK\nContent-Type: application/json; "
                "charset=utf-8\nAccess-Control-Allow-Origin: "
                "*\nAccess-Control-Allow-Methods: POST, GET, "
                "OPTIONS\nContent-Length: 9\n\nokokok!!!");
  if (success) {
    write(clientfd, send, strlen(send));
  }
  if (input != NULL) {
    free(input);
  }
  close(clientfd);
}


x86 assembly (clang, -O0):
<closefd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1070 <sprintf@plt>
cmpl   $0x0,-0x14(%rbp)
je     11b9 <closefd+0x69>
mov    -0x4(%rbp),%eax
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x42c(%rbp),%edi
mov    -0x428(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmpq   $0x0,-0x10(%rbp)
je     11cd <closefd+0x7d>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
call   1060 <close@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<closefd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xe96(%rip),%rsi
mov    %rsp,%rdi
mov    $0xab,%edx
call   1070 <memcpy@plt>
test   %ebp,%ebp
je     1193 <closefd+0x43>
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %rbx,%rbx
je     11a0 <closefd+0x50>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1060 <close@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [171 x i8] c"HTTP/1.1 200 OK\0AContent-Type: application/json; charset=utf-8\0AAccess-Control-Allow-Origin: *\0AAccess-Control-Allow-Methods: POST, GET, OPTIONS\0AContent-Length: 9\0A\0Aokokok!!!\00"
define void @closefd(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1024 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%9 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([171 x i8], [171 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %3
%13 = load i32, i32* %4
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @write(i32 %13, i8* %14, i32 %16)
br label %18
18: ; preds = %12, %3
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %5
%23 = call i32 @free(i8* %22)
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %4
%26 = call i32 @close(i32 %25)
ret void
}

LLVM IR (-O2):
@.str = [171 x i8] c"HTTP/1.1 200 OK\0AContent-Type: application/json; charset=utf-8\0AAccess-Control-Allow-Origin: *\0AAccess-Control-Allow-Methods: POST, GET, OPTIONS\0AContent-Length: 9\0A\0Aokokok!!!\00"
define void @closefd(i32 %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32 %2, 0
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = call i32 @strlen(i8* %5)
%9 = call i32 @write(i32 %0, i8* %5, i32 %8)
br label %10
10: ; preds = %7, %3
%11 = icmp eq i8* %1, null
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = call i32 @free(i8* %1)
br label %14
14: ; preds = %12, %10
%15 = call i32 @close(i32 %0)
ret void
}