#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int length;
};
struct TYPE_4__ {
  TYPE_1__ data;
};
struct iw_event {
  int len;
  TYPE_2__ u;
};

/* Variables and functions */
int IW_EV_LCP_LEN;
int IW_EV_LCP_PK_LEN;
int IW_EV_POINT_LEN;
int IW_EV_POINT_OFF;
int IW_EV_POINT_PK_LEN;
scalar_t__ likely(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *iwe_stream_add_point(char *stream, char *ends, struct iw_event *iwe,
                           char *extra) {
  int event_len = IW_EV_POINT_LEN + iwe->u.data.length;
  if (likely((stream + event_len) < ends)) {
    iwe->len = event_len;
    memcpy(stream, (char *)iwe, IW_EV_LCP_PK_LEN);
    memcpy(stream + IW_EV_LCP_LEN,
           ((char *)iwe) + IW_EV_LCP_LEN + IW_EV_POINT_OFF,
           IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
    memcpy(stream + IW_EV_POINT_LEN, extra, iwe->u.data.length);
    stream += event_len;
  }
  return stream;
}


x86 assembly (clang, -O0):
<iwe_stream_add_point>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    -0x18(%rbp),%rcx
add    0x4(%rcx),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
cmp    -0x10(%rbp),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <likely@plt>
cmp    $0x0,%rax
je     1208 <iwe_stream_add_point+0xe8>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e57(%rip),%rax
mov    (%rax),%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e5d(%rip),%rax
movslq (%rax),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e4c(%rip),%rax
movslq (%rax),%rax
add    %rax,%rsi
mov    0x2e0f(%rip),%rax
movslq (%rax),%rax
add    %rax,%rsi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    0x2e11(%rip),%rax
sub    (%rax),%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    0x2df7(%rip),%rax
movslq (%rax),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edx
call   1030 <memcpy@plt>
mov    -0x24(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iwe_stream_add_point>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rdi,%r12
mov    0x2e9d(%rip),%r13
movslq 0x0(%r13),%rax
movslq 0x4(%rdx),%rbp
add    %rax,%rbp
lea    (%rdi,%rbp,1),%r15
xor    %edi,%edi
cmp    %rsi,%r15
setb   %dil
call   1040 <likely@plt>
test   %rax,%rax
je     11b7 <iwe_stream_add_point+0x97>
mov    %ebp,(%rbx)
mov    0x2e7a(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <memcpy@plt>
mov    0x2e7d(%rip),%rax
movslq (%rax),%rax
lea    (%r12,%rax,1),%rdi
add    %rbx,%rax
mov    0x2e3c(%rip),%rcx
movslq (%rcx),%rsi
add    %rax,%rsi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
sub    0x0(%rbp),%edx
call   1030 <memcpy@plt>
movslq 0x0(%r13),%rdi
add    %r12,%rdi
mov    0x4(%rbx),%edx
mov    %r14,%rsi
call   1030 <memcpy@plt>
jmp    11ba <iwe_stream_add_point+0x9a>
mov    %r12,%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iw_event = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
@IW_EV_POINT_LEN = global i32 0
@IW_EV_LCP_PK_LEN = global i32 0
@IW_EV_LCP_LEN = global i32 0
@IW_EV_POINT_OFF = global i32 0
@IW_EV_POINT_PK_LEN = global i32 0
define i8* @iwe_stream_add_point(i8* %0, i8* %1, %struct.iw_event* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.iw_event*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store %struct.iw_event* %2, %struct.iw_event** %7
store i8* %3, i8** %8
%10 = load i32, i32* @IW_EV_POINT_LEN
%11 = load %struct.iw_event*, %struct.iw_event** %7
%12 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %11, i32 0, i32 1
%13 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %12, i32 0, i32 0
%14 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = add nsw i32 %10, %15
store i32 %16, i32* %9
%17 = load i8*, i8** %5
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8*, i8** %6
%22 = icmp ult i8* %20, %21
%23 = zext i1 %22 to i32
%24 = call i64 @likely(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %66
26: ; preds = %4
%27 = load i32, i32* %9
%28 = load %struct.iw_event*, %struct.iw_event** %7
%29 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i8*, i8** %5
%31 = load %struct.iw_event*, %struct.iw_event** %7
%32 = bitcast %struct.iw_event* %31 to i8*
%33 = load i32, i32* @IW_EV_LCP_PK_LEN
%34 = call i32 @memcpy(i8* %30, i8* %32, i32 %33)
%35 = load i8*, i8** %5
%36 = load i32, i32* @IW_EV_LCP_LEN
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load %struct.iw_event*, %struct.iw_event** %7
%40 = bitcast %struct.iw_event* %39 to i8*
%41 = load i32, i32* @IW_EV_LCP_LEN
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = load i32, i32* @IW_EV_POINT_OFF
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i32, i32* @IW_EV_POINT_PK_LEN
%48 = load i32, i32* @IW_EV_LCP_PK_LEN
%49 = sub nsw i32 %47, %48
%50 = call i32 @memcpy(i8* %38, i8* %46, i32 %49)
%51 = load i8*, i8** %5
%52 = load i32, i32* @IW_EV_POINT_LEN
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8*, i8** %8
%56 = load %struct.iw_event*, %struct.iw_event** %7
%57 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %56, i32 0, i32 1
%58 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %57, i32 0, i32 0
%59 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %58, i32 0, i32 0
%60 = load i32, i32* %59
%61 = call i32 @memcpy(i8* %54, i8* %55, i32 %60)
%62 = load i32, i32* %9
%63 = load i8*, i8** %5
%64 = sext i32 %62 to i64
%65 = getelementptr inbounds i8, i8* %63, i64 %64
store i8* %65, i8** %5
br label %66
66: ; preds = %26, %4
%67 = load i8*, i8** %5
ret i8* %67
}

LLVM IR (-O2):
%struct.iw_event = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
@IW_EV_POINT_LEN = global i32 0
@IW_EV_LCP_PK_LEN = global i32 0
@IW_EV_LCP_LEN = global i32 0
@IW_EV_POINT_OFF = global i32 0
@IW_EV_POINT_PK_LEN = global i32 0
define i8* @iwe_stream_add_point(i8* %0, i8* readnone %1, %struct.iw_event* %2, i8* %3) {
%5 = load i32, i32* @IW_EV_POINT_LEN
%6 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %2, i64 0, i32 1, i32 0, i32 0
%7 = load i32, i32* %6
%8 = add nsw i32 %7, %5
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = icmp ult i8* %10, %1
%12 = zext i1 %11 to i32
%13 = tail call i64 @likely(i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %36, label %15
15: ; preds = %4
%16 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %2, i64 0, i32 0
store i32 %8, i32* %16
%17 = bitcast %struct.iw_event* %2 to i8*
%18 = load i32, i32* @IW_EV_LCP_PK_LEN
%19 = tail call i32 @memcpy(i8* %0, i8* %17, i32 %18)
%20 = load i32, i32* @IW_EV_LCP_LEN
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = getelementptr inbounds i8, i8* %17, i64 %21
%24 = load i32, i32* @IW_EV_POINT_OFF
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i32, i32* @IW_EV_POINT_PK_LEN
%28 = load i32, i32* @IW_EV_LCP_PK_LEN
%29 = sub nsw i32 %27, %28
%30 = tail call i32 @memcpy(i8* %22, i8* %26, i32 %29)
%31 = load i32, i32* @IW_EV_POINT_LEN
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %0, i64 %32
%34 = load i32, i32* %6
%35 = tail call i32 @memcpy(i8* %33, i8* %3, i32 %34)
br label %36
36: ; preds = %15, %4
%37 = phi i8* [ %10, %15 ], [ %0, %4 ]
ret i8* %37
}