#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 *, char *, char);
int addOption(unsigned char **optionptr, char *data, char datalength) {
  unsigned char *tmpptr;
  tmpptr = *optionptr;
  if (datalength != 0) {
    tmpptr[0] = datalength;
  }
  tmpptr++;
  memcpy(tmpptr, data, datalength);
  tmpptr += datalength;
  *optionptr = tmpptr;
  return 0;
}


x86 assembly (clang, -O0):
<addOption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
je     1146 <addOption+0x36>
mov    -0x11(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x11(%rbp),%al
movsbl %al,%edx
call   1030 <memcpy@plt>
movsbl -0x11(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addOption>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rdi,%r14
mov    (%rdi),%rbx
test   %bpl,%bpl
je     1124 <addOption+0x14>
mov    %bpl,(%rbx)
lea    0x1(%rbx),%rdi
movsbl %bpl,%edx
call   1030 <memcpy@plt>
movsbq %bpl,%rax
add    %rbx,%rax
add    $0x1,%rax
mov    %rax,(%r14)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @addOption(i8** %0, i8* %1, i8 signext %2) {
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i8*
store i8** %0, i8*** %4
store i8* %1, i8** %5
store i8 %2, i8* %6
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
store i8* %9, i8** %7
%10 = load i8, i8* %6
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i8, i8* %6
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 %14, i8* %16
br label %17
17: ; preds = %13, %3
%18 = load i8*, i8** %7
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = load i8*, i8** %5
%22 = load i8, i8* %6
%23 = call i32 @memcpy(i8* %20, i8* %21, i8 signext %22)
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
%26 = load i8*, i8** %7
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8, i8* %26, i64 %27
store i8* %28, i8** %7
%29 = load i8*, i8** %7
%30 = load i8**, i8*** %4
store i8* %29, i8** %30
ret i32 0
}

LLVM IR (-O2):
define i32 @addOption(i8** nocapture %0, i8* %1, i8 signext %2) {
%4 = load i8*, i8** %0
%5 = icmp eq i8 %2, 0
br i1 %5, label %7, label %6
6: ; preds = %3
store i8 %2, i8* %4
br label %7
7: ; preds = %6, %3
%8 = getelementptr inbounds i8, i8* %4, i64 1
%9 = tail call i32 @memcpy(i8* %8, i8* %1, i8 signext %2)
%10 = sext i8 %2 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
store i8* %11, i8** %0
ret i32 0
}