#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 */
scalar_t__ likely(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *iwe_stream_add_event(char *stream, char *ends, struct iw_event *iwe,
                           int event_len) {
  if (likely((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
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <likely@plt>
cmp    $0x0,%rax
je     1187 <iwe_stream_add_event+0x67>
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   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %rdi,%rbp
movslq %ecx,%rbx
add    %rdi,%rbx
xor    %edi,%edi
cmp    %rsi,%rbx
setb   %dil
call   1040 <likely@plt>
test   %rax,%rax
je     115c <iwe_stream_add_event+0x3c>
mov    %r15d,(%r14)
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <memcpy@plt>
jmp    115f <iwe_stream_add_event+0x3f>
mov    %rbp,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
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
%15 = zext i1 %14 to i32
%16 = call i64 @likely(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %31
18: ; preds = %4
%19 = load i32, i32* %8
%20 = load %struct.iw_event*, %struct.iw_event** %7
%21 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = load i8*, i8** %5
%23 = load %struct.iw_event*, %struct.iw_event** %7
%24 = bitcast %struct.iw_event* %23 to i8*
%25 = load i32, i32* %8
%26 = call i32 @memcpy(i8* %22, i8* %24, i32 %25)
%27 = load i32, i32* %8
%28 = load i8*, i8** %5
%29 = sext i32 %27 to i64
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8* %30, i8** %5
br label %31
31: ; preds = %18, %4
%32 = load i8*, i8** %5
ret i8* %32
}

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
%8 = zext i1 %7 to i32
%9 = tail call i64 @likely(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %4
%12 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %2, i64 0, i32 0
store i32 %3, i32* %12
%13 = bitcast %struct.iw_event* %2 to i8*
%14 = tail call i32 @memcpy(i8* %0, i8* %13, i32 %3)
br label %15
15: ; preds = %11, %4
%16 = phi i8* [ %6, %11 ], [ %0, %4 ]
ret i8* %16
}