#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 */
char *malloc(scalar_t__);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *parse_cli(int argc, char **argv) {
  char *filename;
  if (argc == 1) {
    filename = malloc(strlen("example.txt") + 1);
    strcpy(filename, "example.txt");
  } else if (argc == 2) {
    filename = malloc(strlen(argv[1]) + 1);
    strcpy(filename, argv[1]);
  } else {
    return NULL;
  }
  return filename;
}


x86 assembly (clang, -O0):
<parse_cli>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    117a <parse_cli+0x4a>
lea    0xeb0(%rip),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c9 <parse_cli+0x99>
cmpl   $0x2,-0xc(%rbp)
jne    11b7 <parse_cli+0x87>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
jmp    11c4 <parse_cli+0x94>
movq   $0x0,-0x8(%rbp)
jmp    11d1 <parse_cli+0xa1>
jmp    11c9 <parse_cli+0x99>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cli>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
je     1157 <parse_cli+0x27>
cmp    $0x1,%edi
jne    117c <parse_cli+0x4c>
mov    $0xc,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xeae(%rip),%rsi
mov    %rax,%rdi
jmp    1175 <parse_cli+0x45>
mov    0x8(%rsi),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    117e <parse_cli+0x4e>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [12 x i8] c"example.txt\00"
define i8* @parse_cli(i32 %0, i8** nocapture %1) {
switch i32 %0, label %13 [
i32 1, label %3
i32 2, label %6
]
3: ; preds = %2
%4 = tail call dereferenceable_or_null(12) i8* @malloc(i64 12)
%5 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %13
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%10 = add nsw i64 %9, 1
%11 = tail call i8* @malloc(i64 %10)
%12 = tail call i32 @strcpy(i8* %11, i8* %8)
br label %13
13: ; preds = %3, %6, %2
%14 = phi i8* [ null, %2 ], [ %4, %3 ], [ %11, %6 ]
ret i8* %14
}