#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*/ EXIT_FAILURE;
scalar_t__ asprintf(char **, char *, char *, char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ stderr;
char *append_cmd(char *old_cmd, const char *cmd) {
  char *s = NULL;
  if (asprintf(&s, "%s%s\n", old_cmd, cmd) < 0) {
    fprintf(stderr, "Cannot append command");
    exit(EXIT_FAILURE);
  }
  free(old_cmd);
  return s;
}


x86 assembly (clang, -O0):
<append_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1050 <asprintf@plt>
cmp    $0x0,%rax
jge    119d <append_cmd+0x5d>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<append_cmd>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rcx
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
lea    0xea5(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
call   1050 <asprintf@plt>
test   %rax,%rax
js     1180 <append_cmd+0x40>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe76(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s%s\0A\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"Cannot append command\00"
@EXIT_FAILURE = global i32 0
define i8* @append_cmd(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %5
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i64 @asprintf(i8** %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32 @free(i8* %16)
%18 = load i8*, i8** %5
ret i8* %18
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s%s\0A\00"
@stderr = global i32 0
@.str.1 = [22 x i8] c"Cannot append command\00"
@EXIT_FAILURE = global i32 0
define i8* @append_cmd(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = call i32 @free(i8* %0)
%14 = load i8*, i8** %3
ret i8* %14
}