#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 uint32_t;

/* Variables and functions */
int ns_crc32(unsigned char *, size_t);
int ntohl(int);
int /*<<< orphan*/ stun_attr_add_str(unsigned char *, size_t *, int,
                                     unsigned char *, int);
int stun_attr_add_fingerprint_str(unsigned char *buf, size_t *len) {
  uint32_t crc32 = 0;
  stun_attr_add_str(buf, len, (0x8028), (unsigned char *)&crc32, 4);
  crc32 = ns_crc32(buf, *len - 8);
  *((uint32_t *)(buf + *len - 4)) = ntohl(crc32 ^ ((uint32_t)0x5354554e));
  return 0;
}


x86 assembly (clang, -O0):
<stun_attr_add_fingerprint_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rcx
mov    $0x8028,%edx
mov    $0x4,%r8d
call   1040 <stun_attr_add_str@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
sub    $0x8,%rsi
call   1030 <ns_crc32@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
xor    $0x5354554e,%edi
call   1050 <ntohl@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    %edx,-0x4(%rax,%rcx,1)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stun_attr_add_fingerprint_str>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rcx
mov    $0x8028,%edx
mov    $0x4,%r8d
call   1040 <stun_attr_add_str@plt>
mov    (%rbx),%rsi
add    $0xfffffffffffffff8,%rsi
mov    %r14,%rdi
call   1030 <ns_crc32@plt>
xor    $0x5354554e,%eax
mov    %eax,%edi
call   1050 <ntohl@plt>
mov    (%rbx),%rcx
mov    %eax,-0x4(%r14,%rcx,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @stun_attr_add_fingerprint_str(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i32
store i8* %0, i8** %3
store i64* %1, i64** %4
store i32 0, i32* %5
%6 = load i8*, i8** %3
%7 = load i64*, i64** %4
%8 = bitcast i32* %5 to i8*
%9 = call i32 @stun_attr_add_str(i8* %6, i64* %7, i32 32808, i8* %8, i32 4)
%10 = load i8*, i8** %3
%11 = load i64*, i64** %4
%12 = load i64, i64* %11
%13 = sub i64 %12, 8
%14 = call i32 @ns_crc32(i8* %10, i64 %13)
store i32 %14, i32* %5
%15 = load i32, i32* %5
%16 = xor i32 %15, 1398035790
%17 = call i32 @ntohl(i32 %16)
%18 = load i8*, i8** %3
%19 = load i64*, i64** %4
%20 = load i64, i64* %19
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 -4
%23 = bitcast i8* %22 to i32*
store i32 %17, i32* %23
ret i32 0
}

LLVM IR (-O2):
define i32 @stun_attr_add_fingerprint_str(i8* %0, i64* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = call i32 @stun_attr_add_str(i8* %0, i64* %1, i32 32808, i8* %4, i32 4)
%6 = load i64, i64* %1
%7 = add i64 %6, -8
%8 = call i32 @ns_crc32(i8* %0, i64 %7)
%9 = xor i32 %8, 1398035790
%10 = call i32 @ntohl(i32 %9)
%11 = load i64, i64* %1
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -4
%14 = bitcast i8* %13 to i32*
store i32 %10, i32* %14
ret i32 0
}