#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 */
struct ns_connection {
  int dummy;
};
typedef int /*<<< orphan*/ chunk_size;

/* Variables and functions */
int /*<<< orphan*/ ns_send(struct ns_connection *, char const *, int);
int snprintf(char *, int, char *, size_t);
void ns_send_http_chunk(struct ns_connection *nc, const char *buf, size_t len) {
  char chunk_size[50];
  int n;
  n = snprintf(chunk_size, sizeof(chunk_size), "%lX\r\n", len);
  ns_send(nc, chunk_size, n);
  ns_send(nc, buf, len);
  ns_send(nc, "\r\n", 2);
}


x86 assembly (clang, -O0):
<ns_send_http_chunk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x32,%esi
lea    0xeb8(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1040 <ns_send@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    %eax,%edx
call   1040 <ns_send@plt>
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
mov    $0x2,%edx
call   1040 <ns_send@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ns_send_http_chunk>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xec5(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x32,%esi
mov    %r15,%rcx
call   1030 <snprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <ns_send@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <ns_send@plt>
lea    0xe93(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1040 <ns_send@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ns_connection = type { i32 }
@.str = [6 x i8] c"%lX\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define void @ns_send_http_chunk(%struct.ns_connection* %0, i8* %1, i64 %2) {
%4 = alloca %struct.ns_connection*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [50 x i8]
%8 = alloca i32
store %struct.ns_connection* %0, %struct.ns_connection** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%10 = load i64, i64* %6
%11 = call i32 @snprintf(i8* %9, i32 50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %10)
store i32 %11, i32* %8
%12 = load %struct.ns_connection*, %struct.ns_connection** %4
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%14 = load i32, i32* %8
%15 = call i32 @ns_send(%struct.ns_connection* %12, i8* %13, i32 %14)
%16 = load %struct.ns_connection*, %struct.ns_connection** %4
%17 = load i8*, i8** %5
%18 = load i64, i64* %6
%19 = trunc i64 %18 to i32
%20 = call i32 @ns_send(%struct.ns_connection* %16, i8* %17, i32 %19)
%21 = load %struct.ns_connection*, %struct.ns_connection** %4
%22 = call i32 @ns_send(%struct.ns_connection* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
ret void
}

LLVM IR (-O2):
%struct.ns_connection = type { i32 }
@.str = [6 x i8] c"%lX\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define void @ns_send_http_chunk(%struct.ns_connection* %0, i8* %1, i64 %2) {
%4 = alloca [50 x i8]
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %2)
%7 = call i32 @ns_send(%struct.ns_connection* %0, i8* %5, i32 %6)
%8 = trunc i64 %2 to i32
%9 = call i32 @ns_send(%struct.ns_connection* %0, i8* %1, i32 %8)
%10 = call i32 @ns_send(%struct.ns_connection* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
ret void
}