#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 */
struct iw_event {
  int len;
};

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char *, int);
char *iwe_stream_add_event(char *stream, char *ends, struct iw_event *iwe,
                           int event_len) {
  if ((stream + event_len) < ends) {
    iwe->len = event_len;
    memcpy(stream, (char *)iwe, event_len);
    stream += event_len;
  }
  return stream;
}


x86 assembly (clang, -O0):
<iwe_stream_add_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
cmp    -0x10(%rbp),%rax
jae    1166 <iwe_stream_add_event+0x56>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iwe_stream_add_event>:
push   %rbx
movslq %ecx,%rbx
add    %rdi,%rbx
cmp    %rsi,%rbx
jae    112a <iwe_stream_add_event+0x1a>
mov    %ecx,(%rdx)
mov    %rdx,%rsi
mov    %ecx,%edx
call   1030 <memcpy@plt>
jmp    112d <iwe_stream_add_event+0x1d>
mov    %rdi,%rbx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.iw_event = type { i32 }
define i8* @iwe_stream_add_event(i8* %0, i8* %1, %struct.iw_event* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.iw_event*
%8 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store %struct.iw_event* %2, %struct.iw_event** %7
store i32 %3, i32* %8
%9 = load i8*, i8** %5
%10 = load i32, i32* %8
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8*, i8** %6
%14 = icmp ult i8* %12, %13
br i1 %14, label %15, label %28
15: ; preds = %4
%16 = load i32, i32* %8
%17 = load %struct.iw_event*, %struct.iw_event** %7
%18 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = load i8*, i8** %5
%20 = load %struct.iw_event*, %struct.iw_event** %7
%21 = bitcast %struct.iw_event* %20 to i8*
%22 = load i32, i32* %8
%23 = call i32 @memcpy(i8* %19, i8* %21, i32 %22)
%24 = load i32, i32* %8
%25 = load i8*, i8** %5
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %25, i64 %26
store i8* %27, i8** %5
br label %28
28: ; preds = %15, %4
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
%struct.iw_event = type { i32 }
define i8* @iwe_stream_add_event(i8* %0, i8* readnone %1, %struct.iw_event* %2, i32 %3) {
%5 = sext i32 %3 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = icmp ult i8* %6, %1
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %2, i64 0, i32 0
store i32 %3, i32* %9
%10 = bitcast %struct.iw_event* %2 to i8*
%11 = tail call i32 @memcpy(i8* %0, i8* %10, i32 %3)
br label %12
12: ; preds = %8, %4
%13 = phi i8* [ %6, %8 ], [ %0, %4 ]
ret i8* %13
}