#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 */

/* Variables and functions */
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned int);
int iDgiAddItem(unsigned char *psDgiBuf, unsigned char *psItem,
                unsigned int uiItemLen) {
  if (uiItemLen > 251)
    return (1);
  if (psDgiBuf[2] + uiItemLen > 251)
    return (1);
  memcpy(psDgiBuf + 3 + psDgiBuf[2], psItem, uiItemLen);
  psDgiBuf[2] += uiItemLen;
  return (0);
}


x86 assembly (clang, -O0):
<iDgiAddItem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
cmpl   $0xfb,-0x1c(%rbp)
jbe    113c <iDgiAddItem+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    1196 <iDgiAddItem+0x86>
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
add    -0x1c(%rbp),%eax
cmp    $0xfb,%eax
jbe    115e <iDgiAddItem+0x4e>
movl   $0x1,-0x4(%rbp)
jmp    1196 <iDgiAddItem+0x86>
mov    -0x10(%rbp),%rdi
add    $0x3,%rdi
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <memcpy@plt>
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movzbl 0x2(%rax),%ecx
add    %edx,%ecx
mov    %cl,0x2(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iDgiAddItem>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%eax
cmp    $0xfb,%edx
ja     114a <iDgiAddItem+0x3a>
mov    %edx,%ebx
mov    %rdi,%r14
movzbl 0x2(%rdi),%ecx
lea    (%rcx,%rbx,1),%edx
cmp    $0xfb,%edx
ja     114a <iDgiAddItem+0x3a>
lea    (%r14,%rcx,1),%rdi
add    $0x3,%rdi
mov    %ebx,%edx
call   1030 <memcpy@plt>
add    %bl,0x2(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @iDgiAddItem(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%8 = load i32, i32* %7
%9 = icmp ugt i32 %8, 251
br i1 %9, label %10, label %11
10: ; preds = %3
store i32 1, i32* %4
br label %39
11: ; preds = %3
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i64 2
%14 = load i8, i8* %13
%15 = zext i8 %14 to i32
%16 = load i32, i32* %7
%17 = add i32 %15, %16
%18 = icmp ugt i32 %17, 251
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 1, i32* %4
br label %39
20: ; preds = %11
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 3
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 2
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %22, i64 %27
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = call i32 @memcpy(i8* %28, i8* %29, i32 %30)
%32 = load i32, i32* %7
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 2
%35 = load i8, i8* %34
%36 = zext i8 %35 to i32
%37 = add i32 %36, %32
%38 = trunc i32 %37 to i8
store i8 %38, i8* %34
store i32 0, i32* %4
br label %39
39: ; preds = %20, %19, %10
%40 = load i32, i32* %4
ret i32 %40
}

LLVM IR (-O2):
define i32 @iDgiAddItem(i8* %0, i8* %1, i32 %2) {
%4 = icmp ugt i32 %2, 251
br i1 %4, label %19, label %5
5: ; preds = %3
%6 = getelementptr inbounds i8, i8* %0, i64 2
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = add nuw nsw i32 %8, %2
%10 = icmp ugt i32 %9, 251
br i1 %10, label %19, label %11
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %0, i64 3
%13 = zext i8 %7 to i64
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = tail call i32 @memcpy(i8* %14, i8* %1, i32 %2)
%16 = load i8, i8* %6
%17 = trunc i32 %2 to i8
%18 = add i8 %16, %17
store i8 %18, i8* %6
br label %19
19: ; preds = %5, %3, %11
%20 = phi i32 [ 0, %11 ], [ 1, %3 ], [ 1, %5 ]
ret i32 %20
}