#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(unsigned short);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int httpPut(char *pAddress, int pPort, char *pRequest,
            unsigned long contentSize) {
  char buffer[0xFFFF];
  int sockId;
  struct sockaddr_in addr;
  struct hostent *hostEntry;
  if ((sockId = (int)socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == 0)
    return 0;
  if ((hostEntry = gethostbyname(pAddress)) == NULL)
    return 0;
  addr.sin_family = AF_INET;
  addr.sin_addr = *((struct in_addr *)*hostEntry->h_addr_list);
  addr.sin_port = htons((unsigned short)pPort);
  if (connect(sockId, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) ==
      -1)
    return 0;
  sprintf(buffer,
          "POST %s HTTP/1.1\r\n"
          "Host: %s\r\n"
          "User-Agent: SPEEDTEST_CLIENT\r\n"
          "Content-Type: application/x-www-form-urlencoded\r\n"
          "Connection: keep-alive\r\n"
          "Content-Length: %lu\r\n"
          "\r\n",
          pRequest, pAddress, 100 * contentSize);
  send(sockId, buffer, strlen(buffer), 0);
  return sockId;
}


x86 assembly (clang, -O0):
<httpPut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10060,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
mov    %eax,-0x10034(%rbp)
cmp    $0x0,%eax
jne    11c5 <httpPut+0x55>
movl   $0x0,-0x4(%rbp)
jmp    12b4 <httpPut+0x144>
mov    -0x10(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x10048(%rbp)
cmp    $0x0,%rax
jne    11eb <httpPut+0x7b>
movl   $0x0,-0x4(%rbp)
jmp    12b4 <httpPut+0x144>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10038(%rbp)
mov    -0x10048(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x1003c(%rbp)
mov    -0x14(%rbp),%eax
movzwl %ax,%edi
call   1040 <htons@plt>
mov    %eax,-0x10040(%rbp)
mov    -0x10034(%rbp),%edi
lea    -0x10040(%rbp),%rsi
mov    $0xc,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
jne    124c <httpPut+0xdc>
movl   $0x0,-0x4(%rbp)
jmp    12b4 <httpPut+0x144>
lea    -0x10030(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
imul   $0x64,-0x28(%rbp),%rax
mov    %eax,%r8d
lea    0xd96(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x10034(%rbp),%eax
mov    %eax,-0x10054(%rbp)
lea    -0x10030(%rbp),%rax
mov    %rax,-0x10050(%rbp)
lea    -0x10030(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x10054(%rbp),%edi
mov    -0x10050(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x10034(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<httpPut>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10028,%rsp
mov    %rcx,%r12
mov    %rdx,0x18(%rsp)
mov    %esi,%r13d
mov    %rdi,%r15
mov    0x2e52(%rip),%r14
mov    (%r14),%edi
mov    0x2e30(%rip),%rax
mov    (%rax),%esi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
call   1090 <socket@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
test   %ebx,%ebx
je     1234 <httpPut+0xc4>
mov    %r15,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     1234 <httpPut+0xc4>
mov    (%r14),%ecx
mov    %ecx,0x10(%rsp)
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
movzwl %r13w,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
je     1234 <httpPut+0xc4>
imul   $0x64,%r12d,%r8d
lea    0xdf9(%rip),%rsi
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    0x18(%rsp),%rdx
mov    %r15,%rcx
call   1070 <sprintf@plt>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %ebx,%ebp
mov    %ebp,%eax
add    $0x10028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [155 x i8] c"POST %s HTTP/1.1\0D\0AHost: %s\0D\0AUser-Agent: SPEEDTEST_CLIENT\0D\0AContent-Type: application/x-www-form-urlencoded\0D\0AConnection: keep-alive\0D\0AContent-Length: %lu\0D\0A\0D\0A\00"
define i32 @httpPut(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca [65535 x i8]
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.hostent*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = load i32, i32* @IPPROTO_TCP
%17 = call i64 @socket(i32 %14, i32 %15, i32 %16)
%18 = trunc i64 %17 to i32
store i32 %18, i32* %11
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 0, i32* %5
br label %60
21: ; preds = %4
%22 = load i8*, i8** %6
%23 = call %struct.hostent* @gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %13
%24 = icmp eq %struct.hostent* %23, null
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 0, i32* %5
br label %60
26: ; preds = %21
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %27, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
%30 = load %struct.hostent*, %struct.hostent** %13
%31 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i32 0, i32 0
%32 = load i64*, i64** %31
%33 = load i64, i64* %32
%34 = inttoptr i64 %33 to %struct.in_addr*
%35 = bitcast %struct.in_addr* %29 to i8*
%36 = bitcast %struct.in_addr* %34 to i8*
%37 = load i32, i32* %7
%38 = trunc i32 %37 to i16
%39 = call i32 @htons(i16 zeroext %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
store i32 %39, i32* %40
%41 = load i32, i32* %11
%42 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%43 = call i32 @connect(i32 %41, %struct.sockaddr* %42, i32 12)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %46
45: ; preds = %26
store i32 0, i32* %5
br label %60
46: ; preds = %26
%47 = getelementptr inbounds [65535 x i8], [65535 x i8]* %10, i64 0, i64 0
%48 = load i8*, i8** %8
%49 = load i8*, i8** %6
%50 = load i64, i64* %9
%51 = mul i64 100, %50
%52 = trunc i64 %51 to i32
%53 = call i32 @sprintf(i8* %47, i8* getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i8* %48, i8* %49, i32 %52)
%54 = load i32, i32* %11
%55 = getelementptr inbounds [65535 x i8], [65535 x i8]* %10, i64 0, i64 0
%56 = getelementptr inbounds [65535 x i8], [65535 x i8]* %10, i64 0, i64 0
%57 = call i32 @strlen(i8* %56)
%58 = call i32 @send(i32 %54, i8* %55, i32 %57, i32 0)
%59 = load i32, i32* %11
store i32 %59, i32* %5
br label %60
60: ; preds = %46, %45, %25, %20
%61 = load i32, i32* %5
ret i32 %61
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str = [155 x i8] c"POST %s HTTP/1.1\0D\0AHost: %s\0D\0AUser-Agent: SPEEDTEST_CLIENT\0D\0AContent-Type: application/x-www-form-urlencoded\0D\0AConnection: keep-alive\0D\0AContent-Length: %lu\0D\0A\0D\0A\00"
define i32 @httpPut(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca [65535 x i8]
%6 = alloca %struct.sockaddr_in
%7 = getelementptr inbounds [65535 x i8], [65535 x i8]* %5, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %6 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = load i32, i32* @IPPROTO_TCP
%12 = tail call i64 @socket(i32 %9, i32 %10, i32 %11)
%13 = trunc i64 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %39, label %15
15: ; preds = %4
%16 = tail call %struct.hostent* @gethostbyname(i8* %0)
%17 = icmp eq %struct.hostent* %16, null
br i1 %17, label %39, label %18
18: ; preds = %15
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i64 0, i32 0
%22 = load i64*, i64** %21
%23 = load i64, i64* %22
%24 = inttoptr i64 %23 to i32*
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1, i32 0
%26 = load i32, i32* %24
store i32 %26, i32* %25
%27 = trunc i32 %1 to i16
%28 = tail call i32 @htons(i16 zeroext %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0
store i32 %28, i32* %29
%30 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%31 = call i32 @connect(i32 %13, %struct.sockaddr* %30, i32 12)
%32 = icmp eq i32 %31, -1
br i1 %32, label %39, label %33
33: ; preds = %18
%34 = trunc i64 %3 to i32
%35 = mul i32 %34, 100
%36 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([155 x i8], [155 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %0, i32 %35)
%37 = call i32 @strlen(i8* %7)
%38 = call i32 @send(i32 %13, i8* %7, i32 %37, i32 0)
br label %39
39: ; preds = %18, %15, %4, %33
%40 = phi i32 [ %13, %33 ], [ 0, %4 ], [ 0, %15 ], [ 0, %18 ]
ret i32 %40
}