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


x86 assembly (clang, -O0):
<addOptionMulti>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %sil,%dl
mov    %rdi,-0x10(%rbp)
mov    %dl,-0x11(%rbp)
mov    %al,-0x12(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%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    116c <addOptionMulti+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    11e8 <addOptionMulti+0xc8>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movsbl -0x12(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11da <addOptionMulti+0xba>
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    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    119b <addOptionMulti+0x7b>
mov    -0x10(%rbp),%rax
movb   $0xff,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addOptionMulti>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8d,%ebx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <endOption@plt>
mov    0x8(%rsp),%rax
mov    %bpl,(%rax)
cmp    $0xff,%bpl
je     11af <addOptionMulti+0x8f>
mov    0x8(%rsp),%rcx
lea    0x1(%rcx),%rax
mov    %rax,0x8(%rsp)
mov    %ebx,%eax
mul    %r15b
mov    %al,0x1(%rcx)
mov    0x8(%rsp),%rdi
add    $0x1,%rdi
mov    %rdi,0x8(%rsp)
test   %ebx,%ebx
jle    11ac <addOptionMulti+0x8c>
movsbq %r15b,%r12
movsbl %r15b,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    0x8(%rsp),%rdi
add    %r12,%rdi
mov    %rdi,0x8(%rsp)
add    $0xffffffff,%ebx
jne    1190 <addOptionMulti+0x70>
movb   $0xff,(%rdi)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @addOptionMulti(i8* %0, i8 zeroext %1, i8 signext %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %7
store i8 %1, i8* %8
store i8 %2, i8* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%13 = call i32 @endOption(i8** %7)
%14 = load i8, i8* %8
%15 = load i8*, i8** %7
%16 = getelementptr inbounds i8, i8* %15, i64 0
store i8 %14, i8* %16
%17 = load i8, i8* %8
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 255
br i1 %19, label %20, label %21
20: ; preds = %5
store i32 0, i32* %6
br label %53
21: ; preds = %5
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %7
%24 = load i8, i8* %9
%25 = sext i8 %24 to i32
%26 = load i32, i32* %11
%27 = mul nsw i32 %25, %26
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i64 0
store i8 %28, i8* %30
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %7
store i32 0, i32* %12
br label %33
33: ; preds = %47, %21
%34 = load i32, i32* %12
%35 = load i32, i32* %11
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %50
37: ; preds = %33
%38 = load i8*, i8** %7
%39 = load i8*, i8** %10
%40 = load i8, i8* %9
%41 = call i32 @memcpy(i8* %38, i8* %39, i8 signext %40)
%42 = load i8, i8* %9
%43 = sext i8 %42 to i32
%44 = load i8*, i8** %7
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8* %46, i8** %7
br label %47
47: ; preds = %37
%48 = load i32, i32* %12
%49 = add nsw i32 %48, 1
store i32 %49, i32* %12
br label %33
50: ; preds = %33
%51 = load i8*, i8** %7
%52 = getelementptr inbounds i8, i8* %51, i64 0
store i8 -1, i8* %52
store i32 0, i32* %6
br label %53
53: ; preds = %50, %20
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
define i32 @addOptionMulti(i8* %0, i8 zeroext %1, i8 signext %2, i8* %3, i32 %4) {
%6 = alloca i8*
store i8* %0, i8** %6
%7 = call i32 @endOption(i8** %6)
%8 = load i8*, i8** %6
store i8 %1, i8* %8
%9 = icmp eq i8 %1, -1
br i1 %9, label %30, label %10
10: ; preds = %5
%11 = load i8*, i8** %6
%12 = getelementptr inbounds i8, i8* %11, i64 1
store i8* %12, i8** %6
%13 = trunc i32 %4 to i8
%14 = mul i8 %13, %2
store i8 %14, i8* %12
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8* %16, i8** %6
%17 = icmp sgt i32 %4, 0
br i1 %17, label %18, label %28
18: ; preds = %10
%19 = sext i8 %2 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i8* [ %16, %18 ], [ %25, %20 ]
%22 = phi i32 [ 0, %18 ], [ %26, %20 ]
%23 = call i32 @memcpy(i8* %21, i8* %3, i8 signext %2)
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 %19
store i8* %25, i8** %6
%26 = add nuw nsw i32 %22, 1
%27 = icmp eq i32 %26, %4
br i1 %27, label %28, label %20
28: ; preds = %20, %10
%29 = phi i8* [ %16, %10 ], [ %25, %20 ]
store i8 -1, i8* %29
br label %30
30: ; preds = %5, %28
ret i32 0
}