#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*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int addopt(char *str1, int pos, char *str2) {
  str1[pos++] = '-';
  strcpy(&str1[pos], str2);
  pos += strlen(str2);
  str1[pos] = ' ';
  return pos + 1;
}


x86 assembly (clang, -O0):
<addopt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
movslq %ecx,%rcx
movb   $0x2d,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addopt>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rdi,%r15
movslq %esi,%rbx
movb   $0x2d,(%rdi,%rbx,1)
add    %rbx,%rdi
add    $0x1,%rdi
mov    %rdx,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rax,1),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x20,(%r15,%rcx,1)
lea    0x2(%rbx,%rax,1),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @addopt(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = add nsw i32 %8, 1
store i32 %9, i32* %5
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
store i8 45, i8* %11
%12 = load i8*, i8** %4
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8*, i8** %6
%17 = call i32 @strcpy(i8* %15, i8* %16)
%18 = load i8*, i8** %6
%19 = call i64 @strlen(i8* %18)
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = add nsw i64 %21, %19
%23 = trunc i64 %22 to i32
store i32 %23, i32* %5
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 32, i8* %27
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
ret i32 %29
}

LLVM IR (-O2):
define i32 @addopt(i8* %0, i32 %1, i8* %2) {
%4 = add nsw i32 %1, 1
%5 = sext i32 %1 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
store i8 45, i8* %6
%7 = sext i32 %4 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = tail call i32 @strcpy(i8* %8, i8* %2)
%10 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%11 = trunc i64 %10 to i32
%12 = add i32 %4, %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
store i8 32, i8* %14
%15 = add nsw i32 %12, 1
ret i32 %15
}