#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 end_option(unsigned char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned char);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned char);
int /*<<< orphan*/ stderr;
int add_option_string(unsigned char *optionptr, unsigned char *string) {
  int end = end_option(optionptr);
  if (end + string[1] + 2 + 1 >= 308) {
    fprintf(stderr, "Option 0x%02x did not fit into the packet!\n", string[0]);
    return 0;
  }
  memcpy(optionptr + end, string, string[1] + 2);
  optionptr[end + string[1] + 2] = 0xFF;
  return string[1] + 2;
}


x86 assembly (clang, -O0):
<add_option_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <end_option@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
add    %ecx,%eax
add    $0x2,%eax
add    $0x1,%eax
cmp    $0x134,%eax
jl     1192 <add_option_string+0x62>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
lea    0xe82(%rip),%rsi
movzbl (%rax),%edx
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11dd <add_option_string+0xad>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x18(%rbp),%rax
movzbl 0x1(%rax),%eax
add    $0x2,%eax
movzbl %al,%edx
call   1050 <memcpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rdx
movzbl 0x1(%rdx),%edx
add    %edx,%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
movzbl 0x1(%rax),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_option_string>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <end_option@plt>
mov    %eax,%r15d
movzbl 0x1(%rbx),%eax
lea    (%r15,%rax,1),%ecx
cmp    $0x131,%ecx
jl     116f <add_option_string+0x3f>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
movzbl (%rbx),%edx
lea    0xe9a(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
jmp    119a <add_option_string+0x6a>
movslq %r15d,%rdi
add    %r14,%rdi
add    $0x2,%al
movzbl %al,%edx
mov    %rbx,%rsi
call   1050 <memcpy@plt>
movzbl 0x1(%rbx),%eax
add    %r15d,%eax
add    $0x2,%eax
cltq
movb   $0xff,(%r14,%rax,1)
movzbl 0x1(%rbx),%eax
add    $0x2,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"Option 0x%02x did not fit into the packet!\0A\00"
define i32 @add_option_string(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = call i32 @end_option(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = load i8*, i8** %5
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = add nsw i32 %9, %13
%15 = add nsw i32 %14, 2
%16 = add nsw i32 %15, 1
%17 = icmp sge i32 %16, 308
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8 zeroext %22)
store i32 0, i32* %3
br label %52
24: ; preds = %2
%25 = load i8*, i8** %4
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8*, i8** %5
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = add nsw i32 %33, 2
%35 = trunc i32 %34 to i8
%36 = call i32 @memcpy(i8* %28, i8* %29, i8 zeroext %35)
%37 = load i8*, i8** %4
%38 = load i32, i32* %6
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = zext i8 %41 to i32
%43 = add nsw i32 %38, %42
%44 = add nsw i32 %43, 2
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %37, i64 %45
store i8 -1, i8* %46
%47 = load i8*, i8** %5
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = add nsw i32 %50, 2
store i32 %51, i32* %3
br label %52
52: ; preds = %24, %18
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"Option 0x%02x did not fit into the packet!\0A\00"
define i32 @add_option_string(i8* %0, i8* %1) {
%3 = tail call i32 @end_option(i8* %0)
%4 = getelementptr inbounds i8, i8* %1, i64 1
%5 = load i8, i8* %4
%6 = zext i8 %5 to i32
%7 = add nsw i32 %3, %6
%8 = icmp sgt i32 %7, 304
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8, i8* %1
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8 zeroext %11)
br label %27
13: ; preds = %2
%14 = sext i32 %3 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = add i8 %5, 2
%17 = tail call i32 @memcpy(i8* %15, i8* %1, i8 zeroext %16)
%18 = load i8, i8* %4
%19 = zext i8 %18 to i32
%20 = add i32 %3, 2
%21 = add i32 %20, %19
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 -1, i8* %23
%24 = load i8, i8* %4
%25 = zext i8 %24 to i32
%26 = add nuw nsw i32 %25, 2
br label %27
27: ; preds = %13, %9
%28 = phi i32 [ 0, %9 ], [ %26, %13 ]
ret i32 %28
}