#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_POINT_LEN;
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 ((stream + event_len) < ends) {
    iwe->len = event_len;
    memcpy(stream, (char *)iwe, IW_EV_POINT_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    0x2eb9(%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
jae    11a1 <iwe_stream_add_point+0x91>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e6e(%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   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdi,%rbx
mov    0x2ec2(%rip),%r13
movslq 0x0(%r13),%rcx
movslq 0x4(%rdx),%rax
add    %rcx,%rax
lea    (%rdi,%rax,1),%r15
cmp    %rsi,%r15
jae    1164 <iwe_stream_add_point+0x54>
mov    %rdx,%r12
mov    %eax,(%rdx)
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <memcpy@plt>
movslq 0x0(%r13),%rdi
add    %rbx,%rdi
mov    0x4(%r12),%edx
mov    %r14,%rsi
call   1030 <memcpy@plt>
jmp    1167 <iwe_stream_add_point+0x57>
mov    %rbx,%r15
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
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
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
br i1 %22, label %23, label %47
23: ; preds = %4
%24 = load i32, i32* %9
%25 = load %struct.iw_event*, %struct.iw_event** %7
%26 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i8*, i8** %5
%28 = load %struct.iw_event*, %struct.iw_event** %7
%29 = bitcast %struct.iw_event* %28 to i8*
%30 = load i32, i32* @IW_EV_POINT_LEN
%31 = call i32 @memcpy(i8* %27, i8* %29, i32 %30)
%32 = load i8*, i8** %5
%33 = load i32, i32* @IW_EV_POINT_LEN
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8*, i8** %8
%37 = load %struct.iw_event*, %struct.iw_event** %7
%38 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %37, i32 0, i32 1
%39 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %38, i32 0, i32 0
%40 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 @memcpy(i8* %35, i8* %36, i32 %41)
%43 = load i32, i32* %9
%44 = load i8*, i8** %5
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8* %46, i8** %5
br label %47
47: ; preds = %23, %4
%48 = load i8*, i8** %5
ret i8* %48
}

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
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
br i1 %11, label %12, label %22
12: ; preds = %4
%13 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %2, i64 0, i32 0
store i32 %8, i32* %13
%14 = bitcast %struct.iw_event* %2 to i8*
%15 = load i32, i32* @IW_EV_POINT_LEN
%16 = tail call i32 @memcpy(i8* %0, i8* %14, i32 %15)
%17 = load i32, i32* @IW_EV_POINT_LEN
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i32, i32* %6
%21 = tail call i32 @memcpy(i8* %19, i8* %3, i32 %20)
br label %22
22: ; preds = %12, %4
%23 = phi i8* [ %10, %12 ], [ %0, %4 ]
ret i8* %23
}