#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*/ endOption(unsigned char **);
int /*<<< orphan*/ memcpy(unsigned char *, char *, char);
int addOption(unsigned char *optionptr, unsigned char code, char datalength,
              char *data) {
  endOption(&optionptr);
  optionptr[0] = code;
  if (code == 0xff)
    return 0;
  optionptr++;
  optionptr[0] = datalength;
  optionptr++;
  memcpy(optionptr, data, datalength);
  optionptr += datalength;
  optionptr[0] = 0xff;
  return 0;
}


x86 assembly (clang, -O0):
<addOption>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %rdi,-0x10(%rbp)
mov    %dl,-0x11(%rbp)
mov    %al,-0x12(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x10(%rbp),%rdi
call   1030 <endOption@plt>
mov    -0x11(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movzbl -0x11(%rbp),%eax
cmp    $0xff,%eax
jne    1168 <addOption+0x48>
movl   $0x0,-0x4(%rbp)
jmp    11bc <addOption+0x9c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x12(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x12(%rbp),%al
movsbl %al,%edx
call   1040 <memcpy@plt>
movsbl -0x12(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0xff,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addOption>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %edx,%ebp
mov    %esi,%ebx
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <endOption@plt>
mov    0x8(%rsp),%rax
mov    %bl,(%rax)
cmp    $0xff,%bl
je     118e <addOption+0x6e>
mov    0x8(%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x8(%rsp)
mov    %bpl,0x1(%rax)
mov    0x8(%rsp),%rdi
add    $0x1,%rdi
mov    %rdi,0x8(%rsp)
movsbl %bpl,%ebx
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    0x8(%rsp),%rax
movsbq %bl,%rcx
lea    (%rax,%rcx,1),%rdx
mov    %rdx,0x8(%rsp)
movb   $0xff,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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