#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 */

/* Variables and functions */
char *gettext(char *);
unsigned short htons(int);
int /*<<< orphan*/ memcpy(char *, void *, unsigned short);
int /*<<< orphan*/ printf(char *, unsigned short);
int /*<<< orphan*/ puts(char *);
void transfer_to_pdu(unsigned char subtype, void *source, char *combinedBeacon,
                     int *currentByte, unsigned short int currentTLVlength) {
  if (1500 < (currentTLVlength + *currentByte + 6)) {
    puts(gettext("Maximum of 1500 Bytes in LAN-Beacon frame exceeded, not all "
                 "information "
                 "will be transmitted. Please include less information."));
    return;
  }
  if (currentTLVlength > 507) {
    printf(gettext("Warning, TLV is %i Bytes long, exceeding maximum of 507 "
                   "characters "
                   "in String. End of string will be cut off."),
           currentTLVlength);
    currentTLVlength = 507;
  }
  unsigned short int TLVheader_combined =
      htons((127 * 0b1000000000) | (currentTLVlength + 4));
  memcpy(&combinedBeacon[*currentByte], &TLVheader_combined, 2);
  combinedBeacon[*currentByte + 2] = 'L' | 0b10000000;
  combinedBeacon[*currentByte + 3] = 'M';
  combinedBeacon[*currentByte + 4] = 'U';
  combinedBeacon[*currentByte + 5] = subtype;
  memcpy(&combinedBeacon[*currentByte + 6], source, currentTLVlength);
  *currentByte = *currentByte + 6 + currentTLVlength;
}


x86 assembly (clang, -O0):
<transfer_to_pdu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %r8w,%ax
mov    %dil,-0x1(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %ax,-0x22(%rbp)
movzwl -0x22(%rbp),%ecx
mov    -0x20(%rbp),%rax
add    (%rax),%ecx
add    $0x6,%ecx
mov    $0x5dc,%eax
cmp    %ecx,%eax
jge    11a3 <transfer_to_pdu+0x53>
lea    0xe6f(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
jmp    128b <transfer_to_pdu+0x13b>
movzwl -0x22(%rbp),%eax
cmp    $0x1fb,%eax
jle    11d0 <transfer_to_pdu+0x80>
lea    0xec5(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
movzwl -0x22(%rbp),%esi
call   1060 <printf@plt>
movw   $0x1fb,-0x22(%rbp)
movzwl -0x22(%rbp),%edi
add    $0x4,%edi
or     $0xfe00,%edi
call   1050 <htons@plt>
mov    %ax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq (%rax),%rax
add    %rax,%rdi
lea    -0x24(%rbp),%rsi
mov    $0x2,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0xcc,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x4d,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x55,(%rax,%rcx,1)
mov    -0x1(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
add    $0x6,%eax
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x22(%rbp),%ax
movzwl %ax,%edx
call   1070 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x6,%ecx
movzwl -0x22(%rbp),%eax
add    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transfer_to_pdu>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    (%rcx),%eax
add    %r8d,%eax
cmp    $0x5d7,%eax
jl     1188 <transfer_to_pdu+0x38>
lea    0xe91(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
mov    %rcx,%rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%r12d
movzwl %r8w,%ebp
cmp    $0x1fc,%ebp
jb     11bb <transfer_to_pdu+0x6b>
lea    0xed7(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
mov    %ebp,%esi
call   1060 <printf@plt>
mov    $0x1fb,%r8w
movzwl %r8w,%ebp
lea    0x4(%rbp),%edi
or     $0xfe00,%edi
call   1050 <htons@plt>
mov    %ax,0xe(%rsp)
movslq (%rbx),%rdi
add    %r15,%rdi
lea    0xe(%rsp),%rsi
mov    $0x2,%edx
call   1070 <memcpy@plt>
movslq (%rbx),%rax
movb   $0xcc,0x2(%rax,%r15,1)
movslq (%rbx),%rax
movb   $0x4d,0x3(%rax,%r15,1)
movslq (%rbx),%rax
movb   $0x55,0x4(%rax,%r15,1)
movslq (%rbx),%rax
mov    %r12b,0x5(%rax,%r15,1)
movslq (%rbx),%rax
lea    (%rax,%r15,1),%rdi
add    $0x6,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
mov    (%rbx),%eax
add    %ebp,%eax
add    $0x6,%eax
mov    %eax,(%rbx)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [126 x i8] c"Maximum of 1500 Bytes in LAN-Beacon frame exceeded, not all information will be transmitted. Please include less information.\00"
@.str.1 = [109 x i8] c"Warning, TLV is %i Bytes long, exceeding maximum of 507 characters in String. End of string will be cut off.\00"
define void @transfer_to_pdu(i8 zeroext %0, i8* %1, i8* %2, i32* %3, i16 zeroext %4) {
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i16
%11 = alloca i16
store i8 %0, i8* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
store i16 %4, i16* %10
%12 = load i16, i16* %10
%13 = zext i16 %12 to i32
%14 = load i32*, i32** %9
%15 = load i32, i32* %14
%16 = add nsw i32 %13, %15
%17 = add nsw i32 %16, 6
%18 = icmp slt i32 1500, %17
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = call i8* @gettext(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @puts(i8* %20)
br label %84
22: ; preds = %5
%23 = load i16, i16* %10
%24 = zext i16 %23 to i32
%25 = icmp sgt i32 %24, 507
br i1 %25, label %26, label %30
26: ; preds = %22
%27 = call i8* @gettext(i8* getelementptr inbounds ([109 x i8], [109 x i8]* @.str.1, i64 0, i64 0))
%28 = load i16, i16* %10
%29 = call i32 @printf(i8* %27, i16 zeroext %28)
store i16 507, i16* %10
br label %30
30: ; preds = %26, %22
%31 = load i16, i16* %10
%32 = zext i16 %31 to i32
%33 = add nsw i32 %32, 4
%34 = or i32 65024, %33
%35 = call zeroext i16 @htons(i32 %34)
store i16 %35, i16* %11
%36 = load i8*, i8** %8
%37 = load i32*, i32** %9
%38 = load i32, i32* %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %36, i64 %39
%41 = bitcast i16* %11 to i8*
%42 = call i32 @memcpy(i8* %40, i8* %41, i16 zeroext 2)
%43 = load i8*, i8** %8
%44 = load i32*, i32** %9
%45 = load i32, i32* %44
%46 = add nsw i32 %45, 2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %43, i64 %47
store i8 -52, i8* %48
%49 = load i8*, i8** %8
%50 = load i32*, i32** %9
%51 = load i32, i32* %50
%52 = add nsw i32 %51, 3
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %49, i64 %53
store i8 77, i8* %54
%55 = load i8*, i8** %8
%56 = load i32*, i32** %9
%57 = load i32, i32* %56
%58 = add nsw i32 %57, 4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %55, i64 %59
store i8 85, i8* %60
%61 = load i8, i8* %6
%62 = load i8*, i8** %8
%63 = load i32*, i32** %9
%64 = load i32, i32* %63
%65 = add nsw i32 %64, 5
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %62, i64 %66
store i8 %61, i8* %67
%68 = load i8*, i8** %8
%69 = load i32*, i32** %9
%70 = load i32, i32* %69
%71 = add nsw i32 %70, 6
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %68, i64 %72
%74 = load i8*, i8** %7
%75 = load i16, i16* %10
%76 = call i32 @memcpy(i8* %73, i8* %74, i16 zeroext %75)
%77 = load i32*, i32** %9
%78 = load i32, i32* %77
%79 = add nsw i32 %78, 6
%80 = load i16, i16* %10
%81 = zext i16 %80 to i32
%82 = add nsw i32 %79, %81
%83 = load i32*, i32** %9
store i32 %82, i32* %83
br label %84
84: ; preds = %30, %19
ret void
}

LLVM IR (-O2):
@.str = [126 x i8] c"Maximum of 1500 Bytes in LAN-Beacon frame exceeded, not all information will be transmitted. Please include less information.\00"
@.str.1 = [109 x i8] c"Warning, TLV is %i Bytes long, exceeding maximum of 507 characters in String. End of string will be cut off.\00"
define void @transfer_to_pdu(i8 zeroext %0, i8* %1, i8* %2, i32* nocapture %3, i16 zeroext %4) {
%6 = alloca i16
%7 = zext i16 %4 to i32
%8 = load i32, i32* %3
%9 = add nsw i32 %8, %7
%10 = icmp sgt i32 %9, 1494
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = tail call i8* @gettext(i8* getelementptr inbounds ([126 x i8], [126 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) %12)
br label %54
14: ; preds = %5
%15 = icmp ugt i16 %4, 507
br i1 %15, label %16, label %19
16: ; preds = %14
%17 = tail call i8* @gettext(i8* getelementptr inbounds ([109 x i8], [109 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @printf(i8* %17, i16 zeroext %4)
br label %19
19: ; preds = %16, %14
%20 = phi i16 [ 507, %16 ], [ %4, %14 ]
%21 = bitcast i16* %6 to i8*
%22 = zext i16 %20 to i32
%23 = add nuw nsw i32 %22, 4
%24 = or i32 %23, 65024
%25 = tail call zeroext i16 @htons(i32 %24)
store i16 %25, i16* %6
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %2, i64 %27
%29 = call i32 @memcpy(i8* %28, i8* %21, i16 zeroext 2)
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %2, i64 %32
store i8 -52, i8* %33
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %2, i64 %36
store i8 77, i8* %37
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %2, i64 %40
store i8 85, i8* %41
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 5
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %2, i64 %44
store i8 %0, i8* %45
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 6
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %2, i64 %48
%50 = call i32 @memcpy(i8* %49, i8* %1, i16 zeroext %20)
%51 = load i32, i32* %3
%52 = add nuw nsw i32 %22, 6
%53 = add i32 %52, %51
store i32 %53, i32* %3
br label %54
54: ; preds = %19, %11
ret void
}