#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 */
typedef int uint8_t;
typedef int uint32_t;
typedef int uint16_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(int *, int, int);
uint32_t put_info_entry(uint16_t type, uint32_t length, uint8_t *p_data,
                        uint8_t *p_dest) {
  if (p_data) {
    uint32_t i = 0;
    uint32_t actual_length = length + 4;
    if (actual_length & 0x03)
      actual_length = (actual_length + 4) & 0xFFFFFFFC;
    memset(&p_dest[i + actual_length - 3], 0xFF, 3);
    p_dest[i++] = (actual_length / 4) & 0xFF;
    p_dest[i++] = (actual_length / 4) >> 8;
    p_dest[i++] = (type & 0xFF);
    p_dest[i++] = (type >> 8);
    memcpy(&p_dest[i], p_data, length);
    return actual_length;
  }
  return 0;
}


x86 assembly (clang, -O0):
<put_info_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     123d <put_info_entry+0x11d>
movl   $0x0,-0x24(%rbp)
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
and    $0x3,%eax
cmp    $0x0,%eax
je     116c <put_info_entry+0x4c>
mov    -0x28(%rbp),%eax
add    $0x4,%eax
and    $0xfffffffc,%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%eax
add    -0x28(%rbp),%eax
sub    $0x3,%eax
cltq
shl    $0x2,%rax
add    %rax,%rdi
mov    $0xff,%esi
mov    $0x3,%edx
call   1030 <memset@plt>
mov    -0x28(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
and    $0xff,%edx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edx
sar    $0x8,%edx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%edx
and    $0xff,%edx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%edx
sar    $0x8,%edx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1244 <put_info_entry+0x124>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<put_info_entry>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdx,%rdx
je     11a5 <put_info_entry+0x85>
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %edi,%r12d
lea    0x4(%r15),%eax
lea    0x8(%r15),%r13d
and    $0xfffffffc,%r13d
test   $0x3,%r15b
cmove  %eax,%r13d
movslq %r13d,%rbp
lea    (%rcx,%rbp,4),%rdi
add    $0xfffffffffffffff4,%rdi
mov    $0xff,%esi
mov    $0x3,%edx
call   1030 <memset@plt>
lea    0x3(%rbp),%eax
test   %ebp,%ebp
cmovns %ebp,%eax
mov    %eax,%ecx
shr    $0x2,%ecx
movzbl %cl,%ecx
mov    %ecx,(%rbx)
sar    $0xa,%eax
mov    %eax,0x4(%rbx)
movzbl %r12b,%eax
mov    %eax,0x8(%rbx)
sar    $0x8,%r12d
mov    %r12d,0xc(%rbx)
add    $0x10,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
jmp    11a8 <put_info_entry+0x88>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @put_info_entry(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%12 = load i32*, i32** %8
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %71
14: ; preds = %4
store i32 0, i32* %10
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 4
store i32 %16, i32* %11
%17 = load i32, i32* %11
%18 = and i32 %17, 3
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i32, i32* %11
%22 = add nsw i32 %21, 4
%23 = and i32 %22, -4
store i32 %23, i32* %11
br label %24
24: ; preds = %20, %14
%25 = load i32*, i32** %9
%26 = load i32, i32* %10
%27 = load i32, i32* %11
%28 = add nsw i32 %26, %27
%29 = sub nsw i32 %28, 3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %25, i64 %30
%32 = call i32 @memset(i32* %31, i32 255, i32 3)
%33 = load i32, i32* %11
%34 = sdiv i32 %33, 4
%35 = and i32 %34, 255
%36 = load i32*, i32** %9
%37 = load i32, i32* %10
%38 = add nsw i32 %37, 1
store i32 %38, i32* %10
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds i32, i32* %36, i64 %39
store i32 %35, i32* %40
%41 = load i32, i32* %11
%42 = sdiv i32 %41, 4
%43 = ashr i32 %42, 8
%44 = load i32*, i32** %9
%45 = load i32, i32* %10
%46 = add nsw i32 %45, 1
store i32 %46, i32* %10
%47 = sext i32 %45 to i64
%48 = getelementptr inbounds i32, i32* %44, i64 %47
store i32 %43, i32* %48
%49 = load i32, i32* %6
%50 = and i32 %49, 255
%51 = load i32*, i32** %9
%52 = load i32, i32* %10
%53 = add nsw i32 %52, 1
store i32 %53, i32* %10
%54 = sext i32 %52 to i64
%55 = getelementptr inbounds i32, i32* %51, i64 %54
store i32 %50, i32* %55
%56 = load i32, i32* %6
%57 = ashr i32 %56, 8
%58 = load i32*, i32** %9
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 1
store i32 %60, i32* %10
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds i32, i32* %58, i64 %61
store i32 %57, i32* %62
%63 = load i32*, i32** %9
%64 = load i32, i32* %10
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i32, i32* %63, i64 %65
%67 = load i32*, i32** %8
%68 = load i32, i32* %7
%69 = call i32 @memcpy(i32* %66, i32* %67, i32 %68)
%70 = load i32, i32* %11
store i32 %70, i32* %5
br label %72
71: ; preds = %4
store i32 0, i32* %5
br label %72
72: ; preds = %71, %24
%73 = load i32, i32* %5
ret i32 %73
}

LLVM IR (-O2):
define i32 @put_info_entry(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = icmp eq i32* %2, null
br i1 %5, label %27, label %6
6: ; preds = %4
%7 = add nsw i32 %1, 4
%8 = and i32 %1, 3
%9 = icmp eq i32 %8, 0
%10 = add nsw i32 %1, 8
%11 = and i32 %10, -4
%12 = select i1 %9, i32 %7, i32 %11
%13 = add nsw i32 %12, -3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %3, i64 %14
%16 = tail call i32 @memset(i32* %15, i32 255, i32 3)
%17 = sdiv i32 %12, 4
%18 = and i32 %17, 255
store i32 %18, i32* %3
%19 = ashr i32 %17, 8
%20 = getelementptr inbounds i32, i32* %3, i64 1
store i32 %19, i32* %20
%21 = and i32 %0, 255
%22 = getelementptr inbounds i32, i32* %3, i64 2
store i32 %21, i32* %22
%23 = ashr i32 %0, 8
%24 = getelementptr inbounds i32, i32* %3, i64 3
store i32 %23, i32* %24
%25 = getelementptr inbounds i32, i32* %3, i64 4
%26 = tail call i32 @memcpy(i32* %25, i32* %2, i32 %1)
br label %27
27: ; preds = %4, %6
%28 = phi i32 [ %12, %6 ], [ 0, %4 ]
ret i32 %28
}