int soapPostSubmit(int fd, const char *url, const char *host,
                   unsigned short port, const char *action, const char *body) {
  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/1.1\r\n"
                         "Host: %s%s\r\n"
                         "User-Agent: POSIX, UPnP/1.0, miniUPnPc/1.0\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, host, portstr, bodysize, action);
  return httpWrite(fd, body, bodysize, headerbuf, headerssize);
}


x86 assembly (clang, -O0):
<soapPostSubmit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x260,%rsp
mov    %cx,%ax
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     1193 <soapPostSubmit+0x63>
lea    -0x24c(%rbp),%rdi
movzwl -0x1a(%rbp),%ecx
mov    $0x8,%esi
lea    0xe74(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x240(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    -0x24c(%rbp),%r9
mov    -0x34(%rbp),%r10d
mov    -0x28(%rbp),%rax
mov    $0x200,%esi
lea    0xe48(%rip),%rdx
mov    %r10d,(%rsp)
mov    %rax,0x8(%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    $0x260,%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>
lea    0xe77(%rip),%rdx
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r9
mov    $0x200,%esi
mov    %r14,%rdi
mov    %r13,%rcx
mov    %r12,%r8
xor    %eax,%eax
push   %r15
push   %rbp
call   1040 <snprintf@plt>
add    $0x10,%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 = [201 x i8] c"POST %s HTTP/1.1\0D\0AHost: %s%s\0D\0AUser-Agent: POSIX, UPnP/1.0, miniUPnPc/1.0\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) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i16
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca [512 x i8]
%15 = alloca i32
%16 = alloca [8 x i8]
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i16 %3, i16* %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%17 = load i8*, i8** %12
%18 = call i64 @strlen(i8* %17)
%19 = trunc i64 %18 to i32
store i32 %19, i32* %13
%20 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 0
store i8 0, i8* %20
%21 = load i16, i16* %10
%22 = zext i16 %21 to i32
%23 = icmp ne i32 %22, 80
br i1 %23, label %24, label %29
24: ; preds = %6
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 0
%26 = load i16, i16* %10
%27 = zext i16 %26 to i32
%28 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %25, i64 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %24, %6
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%31 = load i8*, i8** %8
%32 = load i8*, i8** %9
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %16, i64 0, i64 0
%34 = load i32, i32* %13
%35 = load i8*, i8** %11
%36 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %30, i64 512, i8* getelementptr inbounds ([201 x i8], [201 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %32, i8* %33, i32 %34, i8* %35)
store i32 %36, i32* %15
%37 = load i32, i32* %7
%38 = load i8*, i8** %12
%39 = load i32, i32* %13
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %14, i64 0, i64 0
%41 = load i32, i32* %15
%42 = call i32 (i32, i8*, i32, i8*, i32, ...) bitcast (i32 (...)* @httpWrite to i32 (i32, i8*, i32, i8*, i32, ...)*)(i32 %37, i8* %38, i32 %39, i8* %40, i32 %41)
ret i32 %42
}

LLVM IR (-O2):
@.str = [5 x i8] c":%hu\00"
@.str.1 = [201 x i8] c"POST %s HTTP/1.1\0D\0AHost: %s%s\0D\0AUser-Agent: POSIX, UPnP/1.0, miniUPnPc/1.0\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) {
%7 = alloca [512 x i8]
%8 = alloca [8 x i8]
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 0
%11 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%12 = trunc i64 %11 to i32
store i8 0, i8* %10
%13 = icmp eq i16 %3, 80
br i1 %13, label %17, label %14
14: ; preds = %6
%15 = zext i16 %3 to i32
%16 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %10, i64 8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %6
%18 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %9, i64 512, i8* getelementptr inbounds ([201 x i8], [201 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %2, i8* %10, i32 %12, i8* %4)
%19 = call i32 (i32, i8*, i32, i8*, i32, ...) bitcast (i32 (...)* @httpWrite to i32 (i32, i8*, i32, i8*, i32, ...)*)(i32 %0, i8* %5, i32 %12, i8* %9, i32 %18)
ret i32 %19
}