#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;
typedef int /*<<< orphan*/ field;

/* Variables and functions */
int ntohl(int);
scalar_t__ stun_attr_add_str(unsigned char *, size_t *, int, unsigned char *,
                             int);
int /*<<< orphan*/ stun_init_request_str(int, unsigned char *, size_t *);
int stun_set_allocate_request_str(unsigned char *buf, size_t *len,
                                  uint32_t lifetime, int address_family,
                                  unsigned char transport) {
  stun_init_request_str((0x0003), buf, len);
  {
    unsigned char field[4];
    field[0] = transport;
    field[1] = 0;
    field[2] = 0;
    field[3] = 0;
    if (stun_attr_add_str(buf, len, (0x0019), field, sizeof(field)) < 0)
      return -1;
  }
  {
    if (lifetime < 1)
      lifetime = (600);
    uint32_t field = ntohl(lifetime);
    if (stun_attr_add_str(buf, len, (0x000D), (unsigned char *)(&field),
                          sizeof(field)) < 0)
      return -1;
  }
  switch (address_family) {
  case (0x01):
  case (0x02): {
    unsigned char field[4];
    field[0] = (unsigned char)address_family;
    field[1] = 0;
    field[2] = 0;
    field[3] = 0;
    if (stun_attr_add_str(buf, len, (0x0017), field, sizeof(field)) < 0)
      return -1;
    break;
  }
  case (0x00):
    break;
  default:
    return -1;
  };
  return 0;
}


x86 assembly (clang, -O0):
<stun_set_allocate_request_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8b,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    $0x3,%edi
call   1040 <stun_init_request_str@plt>
mov    -0x21(%rbp),%al
mov    %al,-0x25(%rbp)
movb   $0x0,-0x24(%rbp)
movb   $0x0,-0x23(%rbp)
movb   $0x0,-0x22(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x25(%rbp),%rcx
mov    $0x19,%edx
mov    $0x4,%r8d
call   1030 <stun_attr_add_str@plt>
cmp    $0x0,%rax
jge    11a2 <stun_set_allocate_request_str+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    1278 <stun_set_allocate_request_str+0x148>
cmpl   $0x1,-0x1c(%rbp)
jge    11b3 <stun_set_allocate_request_str+0x83>
movl   $0x258,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x2c(%rbp),%rcx
mov    $0xd,%edx
mov    $0x4,%r8d
call   1030 <stun_attr_add_str@plt>
cmp    $0x0,%rax
jge    11f0 <stun_set_allocate_request_str+0xc0>
movl   $0xffffffff,-0x4(%rbp)
jmp    1278 <stun_set_allocate_request_str+0x148>
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
test   %eax,%eax
je     1260 <stun_set_allocate_request_str+0x130>
jmp    1203 <stun_set_allocate_request_str+0xd3>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
sub    $0x1,%eax
ja     1265 <stun_set_allocate_request_str+0x135>
jmp    1217 <stun_set_allocate_request_str+0xe7>
mov    -0x20(%rbp),%eax
mov    %al,-0x30(%rbp)
movb   $0x0,-0x2f(%rbp)
movb   $0x0,-0x2e(%rbp)
movb   $0x0,-0x2d(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rcx
mov    $0x17,%edx
mov    $0x4,%r8d
call   1030 <stun_attr_add_str@plt>
cmp    $0x0,%rax
jge    125b <stun_set_allocate_request_str+0x12b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1278 <stun_set_allocate_request_str+0x148>
jmp    1271 <stun_set_allocate_request_str+0x141>
jmp    1271 <stun_set_allocate_request_str+0x141>
movl   $0xffffffff,-0x4(%rbp)
jmp    1278 <stun_set_allocate_request_str+0x148>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stun_set_allocate_request_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%ebx
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%r13
mov    %rdi,%rbp
mov    $0x3,%edi
mov    %rbp,%rsi
mov    %r13,%rdx
call   1040 <stun_init_request_str@plt>
mov    %bl,0x10(%rsp)
movw   $0x0,0x11(%rsp)
movb   $0x0,0x13(%rsp)
lea    0x10(%rsp),%rcx
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x19,%edx
mov    $0x4,%r8d
call   1030 <stun_attr_add_str@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
js     1205 <stun_set_allocate_request_str+0xd5>
test   %r12d,%r12d
mov    $0x258,%edi
cmovg  %r12d,%edi
call   1050 <ntohl@plt>
mov    %eax,0x14(%rsp)
lea    0x14(%rsp),%rcx
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0xd,%edx
mov    $0x4,%r8d
call   1030 <stun_attr_add_str@plt>
test   %rax,%rax
js     1205 <stun_set_allocate_request_str+0xd5>
lea    -0x1(%r15),%eax
cmp    $0x2,%eax
jae    1217 <stun_set_allocate_request_str+0xe7>
mov    %r15b,0xc(%rsp)
movw   $0x0,0xd(%rsp)
movb   $0x0,0xf(%rsp)
lea    0xc(%rsp),%rcx
mov    %rbp,%rdi
mov    %r13,%rsi
mov    $0x17,%edx
mov    $0x4,%r8d
call   1030 <stun_attr_add_str@plt>
test   %rax,%rax
js     1205 <stun_set_allocate_request_str+0xd5>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
test   %r15d,%r15d
je     1202 <stun_set_allocate_request_str+0xd2>
jmp    1205 <stun_set_allocate_request_str+0xd5>

LLVM IR (-O0):
define i32 @stun_set_allocate_request_str(i8* %0, i64* %1, i32 %2, i32 %3, i8 zeroext %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca [4 x i8]
%13 = alloca i32
%14 = alloca [4 x i8]
store i8* %0, i8** %7
store i64* %1, i64** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i8 %4, i8* %11
%15 = load i8*, i8** %7
%16 = load i64*, i64** %8
%17 = call i32 @stun_init_request_str(i32 3, i8* %15, i64* %16)
%18 = load i8, i8* %11
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
store i8 %18, i8* %19
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 1
store i8 0, i8* %20
%21 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 2
store i8 0, i8* %21
%22 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 3
store i8 0, i8* %22
%23 = load i8*, i8** %7
%24 = load i64*, i64** %8
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %12, i64 0, i64 0
%26 = call i64 @stun_attr_add_str(i8* %23, i64* %24, i32 25, i8* %25, i32 4)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %5
store i32 -1, i32* %6
br label %61
29: ; preds = %5
%30 = load i32, i32* %9
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 600, i32* %9
br label %33
33: ; preds = %32, %29
%34 = load i32, i32* %9
%35 = call i32 @ntohl(i32 %34)
store i32 %35, i32* %13
%36 = load i8*, i8** %7
%37 = load i64*, i64** %8
%38 = bitcast i32* %13 to i8*
%39 = call i64 @stun_attr_add_str(i8* %36, i64* %37, i32 13, i8* %38, i32 4)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %33
store i32 -1, i32* %6
br label %61
42: ; preds = %33
%43 = load i32, i32* %10
switch i32 %43, label %59 [
i32 1, label %44
i32 2, label %44
i32 0, label %58
]
44: ; preds = %42, %42
%45 = load i32, i32* %10
%46 = trunc i32 %45 to i8
%47 = getelementptr inbounds [4 x i8], [4 x i8]* %14, i64 0, i64 0
store i8 %46, i8* %47
%48 = getelementptr inbounds [4 x i8], [4 x i8]* %14, i64 0, i64 1
store i8 0, i8* %48
%49 = getelementptr inbounds [4 x i8], [4 x i8]* %14, i64 0, i64 2
store i8 0, i8* %49
%50 = getelementptr inbounds [4 x i8], [4 x i8]* %14, i64 0, i64 3
store i8 0, i8* %50
%51 = load i8*, i8** %7
%52 = load i64*, i64** %8
%53 = getelementptr inbounds [4 x i8], [4 x i8]* %14, i64 0, i64 0
%54 = call i64 @stun_attr_add_str(i8* %51, i64* %52, i32 23, i8* %53, i32 4)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %44
store i32 -1, i32* %6
br label %61
57: ; preds = %44
br label %60
58: ; preds = %42
br label %60
59: ; preds = %42
store i32 -1, i32* %6
br label %61
60: ; preds = %58, %57
store i32 0, i32* %6
br label %61
61: ; preds = %60, %59, %56, %41, %28
%62 = load i32, i32* %6
ret i32 %62
}

LLVM IR (-O2):
define i32 @stun_set_allocate_request_str(i8* %0, i64* %1, i32 %2, i32 %3, i8 zeroext %4) {
%6 = alloca [4 x i8]
%7 = alloca i32
%8 = alloca [4 x i8]
%9 = tail call i32 @stun_init_request_str(i32 3, i8* %0, i64* %1)
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 0
store i8 %4, i8* %10
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 1
store i8 0, i8* %11
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 2
store i8 0, i8* %12
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %6, i64 0, i64 3
store i8 0, i8* %13
%14 = call i64 @stun_attr_add_str(i8* %0, i64* %1, i32 25, i8* %10, i32 4)
%15 = icmp sgt i64 %14, -1
br i1 %15, label %16, label %33
16: ; preds = %5
%17 = icmp slt i32 %2, 1
%18 = select i1 %17, i32 600, i32 %2
%19 = bitcast i32* %7 to i8*
%20 = call i32 @ntohl(i32 %18)
store i32 %20, i32* %7
%21 = call i64 @stun_attr_add_str(i8* %0, i64* %1, i32 13, i8* %19, i32 4)
%22 = icmp sgt i64 %21, -1
br i1 %22, label %23, label %33
23: ; preds = %16
switch i32 %3, label %33 [
i32 1, label %24
i32 2, label %24
i32 0, label %32
]
24: ; preds = %23, %23
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%26 = trunc i32 %3 to i8
store i8 %26, i8* %25
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 1
store i8 0, i8* %27
%28 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 2
store i8 0, i8* %28
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
store i8 0, i8* %29
%30 = call i64 @stun_attr_add_str(i8* %0, i64* %1, i32 23, i8* %25, i32 4)
%31 = icmp slt i64 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %24, %23
br label %33
33: ; preds = %24, %16, %5, %23, %32
%34 = phi i32 [ -1, %5 ], [ -1, %16 ], [ 0, %32 ], [ -1, %24 ], [ -1, %23 ]
ret i32 %34
}