int sendMessage(int sock, char *message) {
  int tr = getTrID();
  int trLen = integerLength(tr);
  int headerLen =
      strlen("MIME-Version: 1.0\r\n") +
      strlen("Content-Type: text/plain; charset=UTF-8\r\n") +
      strlen("X-MMS-IM-Format: FN=Arial; EF=I; CO=0; CS=0; PF=22\r\n") +
      strlen("\r\n") + strlen(message);
  char *line1 = malloc(strlen("MSG ") + trLen + strlen(" A ") +
                       integerLength(headerLen) + strlen("\r\n"));
  sprintf(line1, "%s%d%s%d%s", "MSG ", tr, " A ", headerLen, "\r\n");
  char *mess = malloc(strlen(line1) + headerLen + 1);
  sprintf(mess, "%s%s%s%s%s", line1, "MIME-Version: 1.0\r\n",
          "Content-Type: text/plain; charset=UTF-8\r\n",
          "X-MMS-IM-Format: FN=Arial; EF=I; CO=0; CS=0; PF=22\r\n", "\r\n");
  return sendData(sock, mess);
}


x86 assembly (clang, -O0):
<sendMessage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getTrID@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x0,%al
call   1060 <integerLength@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x72,%rax
mov    %eax,-0x1c(%rbp)
movslq -0x18(%rbp),%rax
add    $0x4,%rax
add    $0x3,%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x0,%al
call   1060 <integerLength@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%r9d
lea    0xe28(%rip),%rsi
lea    0xe2c(%rip),%rdx
lea    0xe2a(%rip),%r8
lea    0xe43(%rip),%rax
mov    %rax,(%rsp)
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xded(%rip),%rsi
lea    0xdf1(%rip),%rcx
lea    0xdfe(%rip),%r8
lea    0xe21(%rip),%r9
lea    0xded(%rip),%rax
mov    %rax,(%rsp)
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    $0x0,%al
call   1080 <sendData@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendMessage>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
xor    %eax,%eax
call   1030 <getTrID@plt>
mov    %eax,%r15d
mov    %eax,%edi
xor    %eax,%eax
call   1060 <integerLength@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
add    $0x72,%ebx
movslq %ebp,%rbp
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <integerLength@plt>
cltq
lea    (%rax,%rbp,1),%rdi
add    $0x9,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbp
lea    0xe76(%rip),%r12
mov    %r12,(%rsp)
lea    0xe3b(%rip),%rsi
lea    0xe3f(%rip),%rdx
lea    0xe3d(%rip),%r8
mov    %rax,%rdi
mov    %r15d,%ecx
mov    %ebx,%r9d
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
movslq %ebx,%rcx
lea    (%rcx,%rax,1),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r12,(%rsp)
lea    0xe0b(%rip),%rsi
lea    0xe0f(%rip),%rcx
lea    0xe1c(%rip),%r8
lea    0xe3f(%rip),%r9
mov    %rax,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <sendData@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"%s%d%s%d%s\00"
@.str.1 = [5 x i8] c"MSG \00"
@.str.2 = [4 x i8] c" A \00"
@.str.3 = [3 x i8] c"\0D\0A\00"
@.str.4 = [11 x i8] c"%s%s%s%s%s\00"
@.str.5 = [20 x i8] c"MIME-Version: 1.0\0D\0A\00"
@.str.6 = [42 x i8] c"Content-Type: text/plain; charset=UTF-8\0D\0A\00"
@.str.7 = [53 x i8] c"X-MMS-IM-Format: FN=Arial; EF=I; CO=0; CS=0; PF=22\0D\0A\00"
define i32 @sendMessage(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%10 = call i32 (...) @getTrID()
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = call i32 (i32, ...) bitcast (i32 (...)* @integerLength to i32 (i32, ...)*)(i32 %11)
store i32 %12, i32* %6
%13 = load i8*, i8** %4
%14 = call i64 @strlen(i8* %13)
%15 = add i64 114, %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %7
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = add i64 4, %18
%20 = add i64 %19, 3
%21 = load i32, i32* %7
%22 = call i32 (i32, ...) bitcast (i32 (...)* @integerLength to i32 (i32, ...)*)(i32 %21)
%23 = sext i32 %22 to i64
%24 = add i64 %20, %23
%25 = add i64 %24, 2
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = load i32, i32* %5
%29 = load i32, i32* %7
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%31 = load i8*, i8** %8
%32 = call i64 @strlen(i8* %31)
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = add i64 %32, %34
%36 = add i64 %35, 1
%37 = call i8* @malloc(i64 %36)
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = load i8*, i8** %8
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* %3
%42 = load i8*, i8** %9
%43 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @sendData to i32 (i32, i8*, ...)*)(i32 %41, i8* %42)
ret i32 %43
}

LLVM IR (-O2):
@.str = [11 x i8] c"%s%d%s%d%s\00"
@.str.1 = [5 x i8] c"MSG \00"
@.str.2 = [4 x i8] c" A \00"
@.str.3 = [3 x i8] c"\0D\0A\00"
@.str.4 = [11 x i8] c"%s%s%s%s%s\00"
@.str.5 = [20 x i8] c"MIME-Version: 1.0\0D\0A\00"
@.str.6 = [42 x i8] c"Content-Type: text/plain; charset=UTF-8\0D\0A\00"
@.str.7 = [53 x i8] c"X-MMS-IM-Format: FN=Arial; EF=I; CO=0; CS=0; PF=22\0D\0A\00"
define i32 @sendMessage(i32 %0, i8* nocapture %1) {
%3 = tail call i32 (...) @getTrID()
%4 = tail call i32 (i32, ...) bitcast (i32 (...)* @integerLength to i32 (i32, ...)*)(i32 %3)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%6 = trunc i64 %5 to i32
%7 = add i32 %6, 114
%8 = sext i32 %4 to i64
%9 = tail call i32 (i32, ...) bitcast (i32 (...)* @integerLength to i32 (i32, ...)*)(i32 %7)
%10 = sext i32 %9 to i64
%11 = add nsw i64 %8, 9
%12 = add nsw i64 %11, %10
%13 = tail call i8* @malloc(i64 %12)
%14 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i64 @strlen(i8* dereferenceable(1) %13)
%16 = sext i32 %7 to i64
%17 = add nsw i64 %16, 1
%18 = add i64 %17, %15
%19 = tail call i8* @malloc(i64 %18)
%20 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %19, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%21 = tail call i32 (i32, i8*, ...) bitcast (i32 (...)* @sendData to i32 (i32, i8*, ...)*)(i32 %0, i8* %19)
ret i32 %21
}