#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 */
struct list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ append(struct list *, char *);
char *malloc(int);
char *optarg;
void forward_opt(struct list *cmd, int opt) {
  char *arg = malloc(3);
  arg[0] = '-';
  arg[1] = opt;
  arg[2] = 0;
  append(cmd, arg);
  if (optarg) {
    append(cmd, optarg);
  }
}


x86 assembly (clang, -O0):
<forward_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <append@plt>
mov    0x2e8c(%rip),%rax
cmpq   $0x0,(%rax)
je     1189 <forward_opt+0x69>
mov    -0x8(%rbp),%rdi
mov    0x2e77(%rip),%rax
mov    (%rax),%rsi
call   1030 <append@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forward_opt>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x3,%edi
call   1040 <malloc@plt>
movb   $0x2d,(%rax)
mov    %bpl,0x1(%rax)
movb   $0x0,0x2(%rax)
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <append@plt>
mov    0x2ea9(%rip),%rax
mov    (%rax),%rsi
test   %rsi,%rsi
je     1165 <forward_opt+0x45>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <append@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.list = type { i32 }
@optarg = global i8* null
define void @forward_opt(%struct.list* %0, i32 %1) {
%3 = alloca %struct.list*
%4 = alloca i32
%5 = alloca i8*
store %struct.list* %0, %struct.list** %3
store i32 %1, i32* %4
%6 = call i8* @malloc(i32 3)
store i8* %6, i8** %5
%7 = load i8*, i8** %5
%8 = getelementptr inbounds i8, i8* %7, i64 0
store i8 45, i8* %8
%9 = load i32, i32* %4
%10 = trunc i32 %9 to i8
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %10, i8* %12
%13 = load i8*, i8** %5
%14 = getelementptr inbounds i8, i8* %13, i64 2
store i8 0, i8* %14
%15 = load %struct.list*, %struct.list** %3
%16 = load i8*, i8** %5
%17 = call i32 @append(%struct.list* %15, i8* %16)
%18 = load i8*, i8** @optarg
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load %struct.list*, %struct.list** %3
%22 = load i8*, i8** @optarg
%23 = call i32 @append(%struct.list* %21, i8* %22)
br label %24
24: ; preds = %20, %2
ret void
}

LLVM IR (-O2):
%struct.list = type { i32 }
@optarg = global i8* null
define void @forward_opt(%struct.list* %0, i32 %1) {
%3 = tail call dereferenceable_or_null(3) i8* @malloc(i32 3)
store i8 45, i8* %3
%4 = trunc i32 %1 to i8
%5 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %4, i8* %5
%6 = getelementptr inbounds i8, i8* %3, i64 2
store i8 0, i8* %6
%7 = tail call i32 @append(%struct.list* %0, i8* %3)
%8 = load i8*, i8** @optarg
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @append(%struct.list* %0, i8* %8)
br label %12
12: ; preds = %10, %2
ret void
}