#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 IW_EV_LCP_LEN;
int IW_EV_LCP_PK_LEN;
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, IW_EV_LCP_PK_LEN);
    memcpy(stream + IW_EV_LCP_LEN, ((char *)iwe) + IW_EV_LCP_LEN,
           event_len - IW_EV_LCP_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     11c0 <iwe_stream_add_event+0xa0>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
call   1030 <memcpy@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e71(%rip),%rax
movslq (%rax),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e60(%rip),%rax
movslq (%rax),%rax
add    %rax,%rsi
mov    -0x1c(%rbp),%edx
mov    0x2e50(%rip),%rax
sub    (%rax),%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,%rbx
movslq %ecx,%rbp
add    %rdi,%rbp
xor    %edi,%edi
cmp    %rsi,%rbp
setb   %dil
call   1040 <likely@plt>
test   %rax,%rax
je     1183 <iwe_stream_add_event+0x63>
mov    %r15d,(%r14)
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <memcpy@plt>
mov    0x2e91(%rip),%rax
movslq (%rax),%rax
add    %rax,%rbx
add    %rax,%r14
sub    %eax,%r15d
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1030 <memcpy@plt>
jmp    1186 <iwe_stream_add_event+0x66>
mov    %rbx,%rbp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iw_event = type { i32 }
@IW_EV_LCP_PK_LEN = global i32 0
@IW_EV_LCP_LEN = global i32 0
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 %44
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* @IW_EV_LCP_PK_LEN
%26 = call i32 @memcpy(i8* %22, i8* %24, i32 %25)
%27 = load i8*, i8** %5
%28 = load i32, i32* @IW_EV_LCP_LEN
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load %struct.iw_event*, %struct.iw_event** %7
%32 = bitcast %struct.iw_event* %31 to i8*
%33 = load i32, i32* @IW_EV_LCP_LEN
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i32, i32* %8
%37 = load i32, i32* @IW_EV_LCP_LEN
%38 = sub nsw i32 %36, %37
%39 = call i32 @memcpy(i8* %30, i8* %35, i32 %38)
%40 = load i32, i32* %8
%41 = load i8*, i8** %5
%42 = sext i32 %40 to i64
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8* %43, i8** %5
br label %44
44: ; preds = %18, %4
%45 = load i8*, i8** %5
ret i8* %45
}

LLVM IR (-O2):
%struct.iw_event = type { i32 }
@IW_EV_LCP_PK_LEN = global i32 0
@IW_EV_LCP_LEN = global i32 0
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 %22, 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 = load i32, i32* @IW_EV_LCP_PK_LEN
%15 = tail call i32 @memcpy(i8* %0, i8* %13, i32 %14)
%16 = load i32, i32* @IW_EV_LCP_LEN
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = getelementptr inbounds i8, i8* %13, i64 %17
%20 = sub nsw i32 %3, %16
%21 = tail call i32 @memcpy(i8* %18, i8* %19, i32 %20)
br label %22
22: ; preds = %11, %4
%23 = phi i8* [ %6, %11 ], [ %0, %4 ]
ret i8* %23
}