#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(int);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
void get_command_line_arg_as_string(char **variable, char *cli_input) {
  *variable = malloc((strlen(cli_input) + 1) * sizeof(char));
  strncpy(*variable, cli_input, strlen(cli_input));
  *(&(*variable)[strlen(cli_input)]) = '\x0';
}


x86 assembly (clang, -O0):
<get_command_line_arg_as_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_command_line_arg_as_string>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,(%r14)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
mov    (%r14),%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @get_command_line_arg_as_string(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
store i8** %0, i8*** %3
store i8* %1, i8** %4
%5 = load i8*, i8** %4
%6 = call i64 @strlen(i8* %5)
%7 = add i64 %6, 1
%8 = mul i64 %7, 1
%9 = trunc i64 %8 to i32
%10 = call i8* @malloc(i32 %9)
%11 = load i8**, i8*** %3
store i8* %10, i8** %11
%12 = load i8**, i8*** %3
%13 = load i8*, i8** %12
%14 = load i8*, i8** %4
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
%17 = call i32 @strncpy(i8* %13, i8* %14, i64 %16)
%18 = load i8**, i8*** %3
%19 = load i8*, i8** %18
%20 = load i8*, i8** %4
%21 = call i64 @strlen(i8* %20)
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 0, i8* %22
ret void
}

LLVM IR (-O2):
define void @get_command_line_arg_as_string(i8** nocapture %0, i8* %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = add i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
store i8* %6, i8** %0
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = tail call i32 @strncpy(i8* %6, i8* %1, i64 %7)
%9 = load i8*, i8** %0
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = getelementptr inbounds i8, i8* %9, i64 %10
store i8 0, i8* %11
ret void
}