#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 */
typedef int /*<<< orphan*/ uint32_t;
typedef scalar_t__ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ ntohl(int /*<<< orphan*/);
scalar_t__ ntohs(scalar_t__);
int /*<<< orphan*/ stun_init_buffer_str(unsigned char *, size_t *);
int /*<<< orphan*/ stun_tid_generate_in_message_str(unsigned char *,
                                                    int /*<<< orphan*/ *);
void old_stun_init_command_str(uint16_t message_type, unsigned char *buf,
                               size_t *len, uint32_t cookie) {
  stun_init_buffer_str(buf, len);
  message_type &= (uint16_t)(0x3FFF);
  ((uint16_t *)buf)[0] = ntohs(message_type);
  ((uint16_t *)buf)[1] = 0;
  ((uint32_t *)buf)[1] = ntohl(cookie);
  stun_tid_generate_in_message_str(buf, NULL);
}


x86 assembly (clang, -O0):
<old_stun_init_command_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stun_init_buffer_str@plt>
mov    -0x8(%rbp),%rax
and    $0x3fff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <ntohs@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    -0x1c(%rbp),%edi
call   1060 <ntohl@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <stun_tid_generate_in_message_str@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<old_stun_init_command_str>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1030 <stun_init_buffer_str@plt>
and    $0x3fff,%ebp
mov    %rbp,%rdi
call   1050 <ntohs@plt>
mov    %rax,(%rbx)
movq   $0x0,0x8(%rbx)
mov    %r14d,%edi
call   1060 <ntohl@plt>
mov    %eax,0x4(%rbx)
mov    %rbx,%rdi
xor    %esi,%esi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <stun_tid_generate_in_message_str@plt>

LLVM IR (-O0):
define void @old_stun_init_command_str(i64 %0, i8* %1, i64* %2, i32 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i32
store i64 %0, i64* %5
store i8* %1, i8** %6
store i64* %2, i64** %7
store i32 %3, i32* %8
%9 = load i8*, i8** %6
%10 = load i64*, i64** %7
%11 = call i32 @stun_init_buffer_str(i8* %9, i64* %10)
%12 = load i64, i64* %5
%13 = and i64 %12, 16383
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = call i64 @ntohs(i64 %14)
%16 = load i8*, i8** %6
%17 = bitcast i8* %16 to i64*
%18 = getelementptr inbounds i64, i64* %17, i64 0
store i64 %15, i64* %18
%19 = load i8*, i8** %6
%20 = bitcast i8* %19 to i64*
%21 = getelementptr inbounds i64, i64* %20, i64 1
store i64 0, i64* %21
%22 = load i32, i32* %8
%23 = call i32 @ntohl(i32 %22)
%24 = load i8*, i8** %6
%25 = bitcast i8* %24 to i32*
%26 = getelementptr inbounds i32, i32* %25, i64 1
store i32 %23, i32* %26
%27 = load i8*, i8** %6
%28 = call i32 @stun_tid_generate_in_message_str(i8* %27, i32* null)
ret void
}

LLVM IR (-O2):
define void @old_stun_init_command_str(i64 %0, i8* %1, i64* %2, i32 %3) {
%5 = tail call i32 @stun_init_buffer_str(i8* %1, i64* %2)
%6 = and i64 %0, 16383
%7 = tail call i64 @ntohs(i64 %6)
%8 = bitcast i8* %1 to i64*
store i64 %7, i64* %8
%9 = getelementptr inbounds i8, i8* %1, i64 8
%10 = bitcast i8* %9 to i64*
store i64 0, i64* %10
%11 = tail call i32 @ntohl(i32 %3)
%12 = getelementptr inbounds i8, i8* %1, i64 4
%13 = bitcast i8* %12 to i32*
store i32 %11, i32* %13
%14 = tail call i32 @stun_tid_generate_in_message_str(i8* %1, i32* null)
ret void
}