int soapPostSubmit(int fd, const char *url, const char *host,
                   unsigned short port, const char *action, const char *body,
                   const char *httpversion) {
  int bodysize;
  char headerbuf[512];
  int headerssize;
  char portstr[8];
  bodysize = (int)strlen(body);
  portstr[0] = '\0';
  if (port != 80)
    snprintf(portstr, sizeof(portstr), ":%hu", port);
  headerssize = snprintf(headerbuf, sizeof(headerbuf),
                         "POST %s HTTP/%s\r\n"
                         "Host: %s%s\r\n"
                         "User-Agent: "
                         "Linux"
                         ", "
                         "UPnP/1.1"
                         ", MiniUPnPc/"
                         "1.9"
                         "\r\n"
                         "Content-Length: %d\r\n"
                         "Content-Type: text/xml\r\n"
                         "SOAPAction: \"%s\"\r\n"
                         "Connection: Close\r\n"
                         "Cache-Control: no-cache\r\n"
                         "Pragma: no-cache\r\n"
                         "\r\n",
                         url, httpversion, host, portstr, bodysize, action);
  return httpWrite(fd, body, bodysize, headerbuf, headerssize);
}


x86 assembly (clang, -O0):
<soapPostSubmit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
mov    %cx,%ax
mov    0x10(%rbp),%rcx
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ax,-0x1a(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
movb   $0x0,-0x24c(%rbp)
movzwl -0x1a(%rbp),%eax
cmp    $0x50,%eax
je     1197 <soapPostSubmit+0x67>
lea    -0x24c(%rbp),%rdi
movzwl -0x1a(%rbp),%ecx
mov    $0x8,%esi
lea    0xe70(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x240(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    0x10(%rbp),%r8
mov    -0x18(%rbp),%r9
lea    -0x24c(%rbp),%r11
mov    -0x34(%rbp),%r10d
mov    -0x28(%rbp),%rax
mov    $0x200,%esi
lea    0xe40(%rip),%rdx
mov    %r11,(%rsp)
mov    %r10d,0x8(%rsp)
mov    %rax,0x10(%rsp)
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x244(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
lea    -0x240(%rbp),%rcx
mov    -0x244(%rbp),%r8d
mov    $0x0,%al
call   1050 <httpWrite@plt>
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<soapPostSubmit>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %r9,%rbx
mov    %r8,%r15
mov    %ecx,%r14d
mov    %rdx,%r12
mov    %rsi,%r13
mov    %edi,0x4(%rsp)
mov    %r9,%rdi
call   1030 <strlen@plt>
mov    %rax,%rbp
movb   $0x0,0x8(%rsp)
cmp    $0x50,%r14w
je     1187 <soapPostSubmit+0x57>
movzwl %r14w,%ecx
lea    0xe8a(%rip),%rdx
lea    0x8(%rsp),%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
sub    $0x8,%rsp
lea    0x10(%rsp),%r10
lea    0xe6e(%rip),%rdx
lea    0x18(%rsp),%r14
mov    $0x200,%esi
mov    %r14,%rdi
mov    %r13,%rcx
mov    0x258(%rsp),%r8
mov    %r12,%r9
xor    %eax,%eax
push   %r15
push   %rbp
push   %r10
call   1040 <snprintf@plt>
add    $0x20,%rsp
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r14,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <httpWrite@plt>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c":%hu\00"
@.str.1 = [200 x i8] c"POST %s HTTP/%s\0D\0AHost: %s%s\0D\0AUser-Agent: Linux, UPnP/1.1, MiniUPnPc/1.9\0D\0AContent-Length: %d\0D\0AContent-Type: text/xml\0D\0ASOAPAction: \22%s\22\0D\0AConnection: Close\0D\0ACache-Control: no-cache\0D\0APragma: no-cache\0D\0A\0D\0A\00"
define i32 @soapPostSubmit(i32 %0, i8* %1, i8* %2, i16 zeroext %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i16
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca [512 x i8]
%17 = alloca i32
%18 = alloca [8 x i8]
store i32 %0, i32* %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i16 %3, i16* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i8* %6, i8** %14
%19 = load i8*, i8** %13
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
store i32 %21, i32* %15
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
store i8 0, i8* %22
%23 = load i16, i16* %11
%24 = zext i16 %23 to i32
%25 = icmp ne i32 %24, 80
br i1 %25, label %26, label %31
26: ; preds = %7
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
%28 = load i16, i16* %11
%29 = zext i16 %28 to i32
%30 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %27, i64 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %26, %7
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%33 = load i8*, i8** %9
%34 = load i8*, i8** %14
%35 = load i8*, i8** %10
%36 = getelementptr inbounds [8 x i8], [8 x i8]* %18, i64 0, i64 0
%37 = load i32, i32* %15
%38 = load i8*, i8** %12
%39 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %32, i64 512, i8* getelementptr inbounds ([200 x i8], [200 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %34, i8* %35, i8* %36, i32 %37, i8* %38)
store i32 %39, i32* %17
%40 = load i32, i32* %8
%41 = load i8*, i8** %13
%42 = load i32, i32* %15
%43 = getelementptr inbounds [512 x i8], [512 x i8]* %16, i64 0, i64 0
%44 = load i32, i32* %17
%45 = call i32 (i32, i8*, i32, i8*, i32, ...) bitcast (i32 (...)* @httpWrite to i32 (i32, i8*, i32, i8*, i32, ...)*)(i32 %40, i8* %41, i32 %42, i8* %43, i32 %44)
ret i32 %45
}

LLVM IR (-O2):
@.str = [5 x i8] c":%hu\00"
@.str.1 = [200 x i8] c"POST %s HTTP/%s\0D\0AHost: %s%s\0D\0AUser-Agent: Linux, UPnP/1.1, MiniUPnPc/1.9\0D\0AContent-Length: %d\0D\0AContent-Type: text/xml\0D\0ASOAPAction: \22%s\22\0D\0AConnection: Close\0D\0ACache-Control: no-cache\0D\0APragma: no-cache\0D\0A\0D\0A\00"
define i32 @soapPostSubmit(i32 %0, i8* %1, i8* %2, i16 zeroext %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca [512 x i8]
%9 = alloca [8 x i8]
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%12 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%13 = trunc i64 %12 to i32
store i8 0, i8* %11
%14 = icmp eq i16 %3, 80
br i1 %14, label %18, label %15
15: ; preds = %7
%16 = zext i16 %3 to i32
%17 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %11, i64 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %7
%19 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %10, i64 512, i8* getelementptr inbounds ([200 x i8], [200 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %6, i8* %2, i8* %11, i32 %13, i8* %4)
%20 = call i32 (i32, i8*, i32, i8*, i32, ...) bitcast (i32 (...)* @httpWrite to i32 (i32, i8*, i32, i8*, i32, ...)*)(i32 %0, i8* %5, i32 %13, i8* %10, i32 %19)
ret i32 %20
}