#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;
scalar_t__ likely(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *iwe_stream_add_value(char *event, char *value, char *ends,
                           struct iw_event *iwe, int event_len) {
  event_len -= IW_EV_LCP_LEN;
  if (likely((value + event_len) < ends)) {
    memcpy(value, (char *)iwe + IW_EV_LCP_LEN, event_len);
    value += event_len;
    iwe->len = value - event;
    memcpy(event, (char *)iwe, IW_EV_LCP_LEN);
  }
  return value;
}


x86 assembly (clang, -O0):
<iwe_stream_add_value>:
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    %r8d,-0x24(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
add    %rcx,%rax
cmp    -0x18(%rbp),%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <likely@plt>
cmp    $0x0,%rax
je     11ca <iwe_stream_add_value+0xaa>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e76(%rip),%rax
movslq (%rax),%rax
add    %rax,%rsi
mov    -0x24(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x24(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
call   1030 <memcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iwe_stream_add_value>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    0x2ebd(%rip),%rbp
movslq 0x0(%rbp),%rax
movslq %r8d,%rbx
sub    %rax,%rbx
lea    (%rsi,%rbx,1),%r13
xor    %edi,%edi
cmp    %rdx,%r13
setb   %dil
call   1040 <likely@plt>
test   %rax,%rax
je     1186 <iwe_stream_add_value+0x66>
movslq 0x0(%rbp),%rsi
add    %r14,%rsi
mov    %r12,%rdi
mov    %ebx,%edx
call   1030 <memcpy@plt>
mov    %r13d,%eax
sub    %r15d,%eax
mov    %eax,(%r14)
mov    0x0(%rbp),%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <memcpy@plt>
jmp    1189 <iwe_stream_add_value+0x69>
mov    %r12,%r13
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iw_event = type { i32 }
@IW_EV_LCP_LEN = global i32 0
define i8* @iwe_stream_add_value(i8* %0, i8* %1, i8* %2, %struct.iw_event* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.iw_event*
%10 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store %struct.iw_event* %3, %struct.iw_event** %9
store i32 %4, i32* %10
%11 = load i32, i32* @IW_EV_LCP_LEN
%12 = load i32, i32* %10
%13 = sub nsw i32 %12, %11
store i32 %13, i32* %10
%14 = load i8*, i8** %7
%15 = load i32, i32* %10
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8*, i8** %8
%19 = icmp ult i8* %17, %18
%20 = zext i1 %19 to i32
%21 = call i64 @likely(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %49
23: ; preds = %5
%24 = load i8*, i8** %7
%25 = load %struct.iw_event*, %struct.iw_event** %9
%26 = bitcast %struct.iw_event* %25 to i8*
%27 = load i32, i32* @IW_EV_LCP_LEN
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i32, i32* %10
%31 = call i32 @memcpy(i8* %24, i8* %29, i32 %30)
%32 = load i32, i32* %10
%33 = load i8*, i8** %7
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %33, i64 %34
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = load i8*, i8** %6
%38 = ptrtoint i8* %36 to i64
%39 = ptrtoint i8* %37 to i64
%40 = sub i64 %38, %39
%41 = trunc i64 %40 to i32
%42 = load %struct.iw_event*, %struct.iw_event** %9
%43 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %42, i32 0, i32 0
store i32 %41, i32* %43
%44 = load i8*, i8** %6
%45 = load %struct.iw_event*, %struct.iw_event** %9
%46 = bitcast %struct.iw_event* %45 to i8*
%47 = load i32, i32* @IW_EV_LCP_LEN
%48 = call i32 @memcpy(i8* %44, i8* %46, i32 %47)
br label %49
49: ; preds = %23, %5
%50 = load i8*, i8** %7
ret i8* %50
}

LLVM IR (-O2):
%struct.iw_event = type { i32 }
@IW_EV_LCP_LEN = global i32 0
define i8* @iwe_stream_add_value(i8* %0, i8* %1, i8* readnone %2, %struct.iw_event* %3, i32 %4) {
%6 = load i32, i32* @IW_EV_LCP_LEN
%7 = sub nsw i32 %4, %6
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = icmp ult i8* %9, %2
%11 = zext i1 %10 to i32
%12 = tail call i64 @likely(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %27, label %14
14: ; preds = %5
%15 = bitcast %struct.iw_event* %3 to i8*
%16 = load i32, i32* @IW_EV_LCP_LEN
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = tail call i32 @memcpy(i8* %1, i8* %18, i32 %7)
%20 = ptrtoint i8* %9 to i64
%21 = ptrtoint i8* %0 to i64
%22 = sub i64 %20, %21
%23 = trunc i64 %22 to i32
%24 = getelementptr inbounds %struct.iw_event, %struct.iw_event* %3, i64 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @IW_EV_LCP_LEN
%26 = tail call i32 @memcpy(i8* %0, i8* %15, i32 %25)
br label %27
27: ; preds = %14, %5
%28 = phi i8* [ %9, %14 ], [ %1, %5 ]
ret i8* %28
}