#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 iw_request_info {
  int dummy;
};
struct TYPE_4__ {
  int length;
};
struct TYPE_3__ {
  TYPE_2__ data;
};
struct iw_event {
  int len;
  TYPE_1__ u;
};

/* Variables and functions */
int IW_EV_LCP_PK_LEN;
int IW_EV_POINT_OFF;
int IW_EV_POINT_PK_LEN;
int iwe_stream_lcp_len(struct iw_request_info *);
int iwe_stream_point_len(struct iw_request_info *);
scalar_t__ likely(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *iwe_stream_add_point(struct iw_request_info *info, char *stream,
                           char *ends, struct iw_event *iwe, char *extra) {
  int event_len = iwe_stream_point_len(info) + iwe->u.data.length;
  int point_len = iwe_stream_point_len(info);
  int lcp_len = iwe_stream_lcp_len(info);
  if (likely((stream + event_len) < ends)) {
    iwe->len = event_len;
    memcpy(stream, (char *)iwe, IW_EV_LCP_PK_LEN);
    memcpy(stream + lcp_len, ((char *)&iwe->u) + IW_EV_POINT_OFF,
           IW_EV_POINT_PK_LEN - IW_EV_LCP_PK_LEN);
    memcpy(stream + 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    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <iwe_stream_point_len@plt>
mov    -0x20(%rbp),%rcx
add    0x4(%rcx),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <iwe_stream_point_len@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <iwe_stream_lcp_len@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
add    %rcx,%rax
cmp    -0x18(%rbp),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <likely@plt>
cmp    $0x0,%rax
je     122f <iwe_stream_add_point+0xef>
mov    -0x2c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rdi
movslq -0x34(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
add    $0x4,%rsi
mov    0x2df2(%rip),%rax
movslq (%rax),%rax
add    %rax,%rsi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
mov    0x2dec(%rip),%rax
sub    (%rax),%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rdi
movslq -0x30(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edx
call   1030 <memcpy@plt>
mov    -0x2c(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iwe_stream_add_point>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,0x10(%rsp)
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbp
call   1060 <iwe_stream_point_len@plt>
movslq 0x4(%rbx),%rcx
movslq %eax,%r13
add    %rcx,%r13
mov    %rbp,%rdi
call   1060 <iwe_stream_point_len@plt>
mov    %eax,0xc(%rsp)
mov    %rbp,%rdi
call   1040 <iwe_stream_lcp_len@plt>
mov    %eax,%ebp
lea    (%r15,%r13,1),%r12
xor    %edi,%edi
cmp    %r14,%r12
setb   %dil
call   1050 <likely@plt>
test   %rax,%rax
je     11f4 <iwe_stream_add_point+0xb4>
lea    0x4(%rbx),%r14
mov    %r13d,(%rbx)
mov    0x2e3f(%rip),%r13
mov    0x0(%r13),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <memcpy@plt>
movslq %ebp,%rdi
add    %r15,%rdi
mov    0x2e13(%rip),%rax
movslq (%rax),%rsi
add    %r14,%rsi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
sub    0x0(%r13),%edx
call   1030 <memcpy@plt>
movslq 0xc(%rsp),%rdi
add    %r15,%rdi
mov    0x4(%rbx),%edx
mov    0x10(%rsp),%rsi
call   1030 <memcpy@plt>
jmp    11f7 <iwe_stream_add_point+0xb7>
mov    %r15,%r12
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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