#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*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *xrealloc(char *, int);
char *add_option(const char *opt, char *options) {
  int oldlen = options ? strlen(options) : 0;
  options = xrealloc(options, oldlen + 1 + strlen(opt) + 1);
  if (!oldlen)
    strcpy(options, opt);
  else {
    strcat(options, ",");
    strcat(options, opt);
  }
  return options;
}


x86 assembly (clang, -O0):
<add_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116c <add_option+0x2c>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
jmp    1176 <add_option+0x36>
xor    %eax,%eax
mov    %eax,-0x18(%rbp)
jmp    1176 <add_option+0x36>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rdi
add    %eax,%esi
add    $0x1,%esi
call   1050 <xrealloc@plt>
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11c7 <add_option+0x87>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11e4 <add_option+0xa4>
mov    -0x10(%rbp),%rdi
lea    0xe2e(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_option>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     115d <add_option+0x1d>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
jmp    1160 <add_option+0x20>
xor    %r15d,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%esi
add    $0x2,%esi
mov    %rbx,%rdi
call   1050 <xrealloc@plt>
mov    %rax,%rbx
test   %r15d,%r15d
je     119b <add_option+0x5b>
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
jmp    11a6 <add_option+0x66>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define i8* @add_option(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%6 = load i8*, i8** %4
%7 = icmp ne i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
br label %12
11: ; preds = %2
br label %12
12: ; preds = %11, %8
%13 = phi i32 [ %10, %8 ], [ 0, %11 ]
store i32 %13, i32* %5
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
%17 = load i8*, i8** %3
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %16, %18
%20 = add nsw i32 %19, 1
%21 = call i8* @xrealloc(i8* %14, i32 %20)
store i8* %21, i8** %4
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %12
%25 = load i8*, i8** %4
%26 = load i8*, i8** %3
%27 = call i32 @strcpy(i8* %25, i8* %26)
br label %34
28: ; preds = %12
%29 = load i8*, i8** %4
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%31 = load i8*, i8** %4
%32 = load i8*, i8** %3
%33 = call i32 @strcat(i8* %31, i8* %32)
br label %34
34: ; preds = %28, %24
%35 = load i8*, i8** %4
ret i8* %35
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define i8* @add_option(i8* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @strlen(i8* %1)
br label %6
6: ; preds = %2, %4
%7 = phi i32 [ %5, %4 ], [ 0, %2 ]
%8 = tail call i32 @strlen(i8* %0)
%9 = add i32 %7, 2
%10 = add i32 %9, %8
%11 = tail call i8* @xrealloc(i8* %1, i32 %10)
%12 = icmp eq i32 %7, 0
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = tail call i32 @strcpy(i8* %11, i8* %0)
br label %18
15: ; preds = %6
%16 = tail call i32 @strcat(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @strcat(i8* %11, i8* %0)
br label %18
18: ; preds = %15, %13
ret i8* %11
}