#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 *check_mem(char *, int *, int);
int /*<<< orphan*/ free(char *);
char *malloc_string(int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *cmd_build(int argc, char **argv) {
  int args_size = 256;
  int files_size = 256;
  int i;
  char *cmd;
  char *args;
  char *files;
  args = malloc_string(args_size);
  files = malloc_string(files_size);
  for (i = 1; i < argc; i++) {
    if (argv[i][0] == '-') {
      args = check_mem(args, &args_size, strlen(argv[i]) + 1);
      strcat(args, " ");
      strcat(args, argv[i]);
    } else {
      files = check_mem(files, &files_size, strlen(argv[i]) + 1);
      strcat(files, " ");
      strcat(files, argv[i]);
    }
  }
  cmd = malloc_string(strlen("ls") + strlen(args) +
                      strlen("-hlv --group-directories-first "
                             "--color=always --time=atime --time-style=+%s") +
                      strlen(files) + 3);
  sprintf(cmd, "%s %s %s %s", "ls", args,
          "-hlv --group-directories-first "
          "--color=always --time=atime --time-style=+%s",
          files);
  free(args);
  free(files);
  return cmd;
}


x86 assembly (clang, -O0):
<cmd_build>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x100,-0x14(%rbp)
movl   $0x100,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <malloc_string@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <malloc_string@plt>
mov    %rax,-0x38(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1280 <cmd_build+0x120>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1219 <cmd_build+0xb9>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
lea    -0x14(%rbp),%rsi
call   1070 <check_mem@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
jmp    126d <cmd_build+0x10d>
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
add    $0x1,%edx
lea    -0x18(%rbp),%rsi
call   1070 <check_mem@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xdad(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
jmp    1272 <cmd_build+0x112>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    119c <cmd_build+0x3c>
lea    0xd7b(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x54(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x54(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x50(%rbp)
lea    0xd5c(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edi
add    %eax,%edi
add    $0x3,%edi
call   1050 <malloc_string@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r9
lea    0xd6c(%rip),%rsi
lea    0xd16(%rip),%rdx
lea    0xd12(%rip),%r8
call   1080 <sprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_build>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movl   $0x100,0x14(%rsp)
movl   $0x100,0x10(%rsp)
mov    $0x100,%edi
call   1050 <malloc_string@plt>
mov    %rax,%r12
mov    $0x100,%edi
call   1050 <malloc_string@plt>
mov    %rax,0x8(%rsp)
cmp    $0x2,%ebp
jl     1218 <cmd_build+0xb8>
mov    %ebp,%ebp
mov    $0x1,%r13d
jmp    11ed <cmd_build+0x8d>
xchg   %ax,%ax
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %eax,%edx
call   1070 <check_mem@plt>
mov    %rax,%r15
mov    %rax,0x8(%rsp)
mov    %r15,%rdi
lea    0xe2d(%rip),%rsi
call   1060 <strcat@plt>
mov    (%r14,%r13,8),%rsi
mov    %r15,%rdi
call   1060 <strcat@plt>
add    $0x1,%r13
cmp    %r13,%rbp
je     1218 <cmd_build+0xb8>
mov    (%r14,%r13,8),%rdi
movzbl (%rdi),%ebx
call   1040 <strlen@plt>
add    $0x1,%eax
cmp    $0x2d,%bl
jne    11b0 <cmd_build+0x50>
mov    %r12,%rdi
lea    0x14(%rsp),%rsi
mov    %eax,%edx
call   1070 <check_mem@plt>
mov    %rax,%r15
mov    %rax,%r12
jmp    11c9 <cmd_build+0x69>
lea    0xde3(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xdcd(%rip),%r13
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
add    %r14d,%ebx
add    %r15d,%ebx
lea    (%rax,%rbx,1),%edi
add    $0x3,%edi
call   1050 <malloc_string@plt>
mov    %rax,%rbx
lea    0xde6(%rip),%rsi
mov    %rax,%rdi
lea    0xd8d(%rip),%rdx
mov    %r12,%rcx
mov    %r13,%r8
mov    %rbp,%r9
call   1080 <sprintf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [76 x i8] c"-hlv --group-directories-first --color=always --time=atime --time-style=+%s\00"
@.str.3 = [12 x i8] c"%s %s %s %s\00"
define i8* @cmd_build(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 256, i32* %5
store i32 256, i32* %6
%11 = load i32, i32* %5
%12 = call i8* @malloc_string(i32 %11)
store i8* %12, i8** %9
%13 = load i32, i32* %6
%14 = call i8* @malloc_string(i32 %13)
store i8* %14, i8** %10
store i32 1, i32* %7
br label %15
15: ; preds = %68, %2
%16 = load i32, i32* %7
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %71
19: ; preds = %15
%20 = load i8**, i8*** %4
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 45
br i1 %28, label %29, label %48
29: ; preds = %19
%30 = load i8*, i8** %9
%31 = load i8**, i8*** %4
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @strlen(i8* %35)
%37 = add nsw i32 %36, 1
%38 = call i8* @check_mem(i8* %30, i32* %5, i32 %37)
store i8* %38, i8** %9
%39 = load i8*, i8** %9
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%41 = load i8*, i8** %9
%42 = load i8**, i8*** %4
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 @strcat(i8* %41, i8* %46)
br label %67
48: ; preds = %19
%49 = load i8*, i8** %10
%50 = load i8**, i8*** %4
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %50, i64 %52
%54 = load i8*, i8** %53
%55 = call i32 @strlen(i8* %54)
%56 = add nsw i32 %55, 1
%57 = call i8* @check_mem(i8* %49, i32* %6, i32 %56)
store i8* %57, i8** %10
%58 = load i8*, i8** %10
%59 = call i32 @strcat(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%60 = load i8*, i8** %10
%61 = load i8**, i8*** %4
%62 = load i32, i32* %7
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8*, i8** %61, i64 %63
%65 = load i8*, i8** %64
%66 = call i32 @strcat(i8* %60, i8* %65)
br label %67
67: ; preds = %48, %29
br label %68
68: ; preds = %67
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %15
71: ; preds = %15
%72 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%73 = load i8*, i8** %9
%74 = call i32 @strlen(i8* %73)
%75 = add nsw i32 %72, %74
%76 = call i32 @strlen(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.2, i64 0, i64 0))
%77 = add nsw i32 %75, %76
%78 = load i8*, i8** %10
%79 = call i32 @strlen(i8* %78)
%80 = add nsw i32 %77, %79
%81 = add nsw i32 %80, 3
%82 = call i8* @malloc_string(i32 %81)
store i8* %82, i8** %8
%83 = load i8*, i8** %8
%84 = load i8*, i8** %9
%85 = load i8*, i8** %10
%86 = call i32 @sprintf(i8* %83, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %84, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.2, i64 0, i64 0), i8* %85)
%87 = load i8*, i8** %9
%88 = call i32 @free(i8* %87)
%89 = load i8*, i8** %10
%90 = call i32 @free(i8* %89)
%91 = load i8*, i8** %8
ret i8* %91
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [76 x i8] c"-hlv --group-directories-first --color=always --time=atime --time-style=+%s\00"
@.str.3 = [12 x i8] c"%s %s %s %s\00"
define i8* @cmd_build(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 256, i32* %3
%6 = bitcast i32* %4 to i8*
store i32 256, i32* %4
%7 = tail call i8* @malloc_string(i32 256)
%8 = tail call i8* @malloc_string(i32 256)
%9 = icmp sgt i32 %0, 1
br i1 %9, label %10, label %35
10: ; preds = %2
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %10, %26
%13 = phi i64 [ 1, %10 ], [ %33, %26 ]
%14 = phi i8* [ %8, %10 ], [ %29, %26 ]
%15 = phi i8* [ %7, %10 ], [ %28, %26 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %13
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 45
%20 = call i32 @strlen(i8* %17)
%21 = add nsw i32 %20, 1
br i1 %19, label %22, label %24
22: ; preds = %12
%23 = call i8* @check_mem(i8* %15, i32* %3, i32 %21)
br label %26
24: ; preds = %12
%25 = call i8* @check_mem(i8* %14, i32* %4, i32 %21)
br label %26
26: ; preds = %22, %24
%27 = phi i8* [ %23, %22 ], [ %25, %24 ]
%28 = phi i8* [ %23, %22 ], [ %15, %24 ]
%29 = phi i8* [ %14, %22 ], [ %25, %24 ]
%30 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%31 = load i8*, i8** %16
%32 = call i32 @strcat(i8* %27, i8* %31)
%33 = add nuw nsw i64 %13, 1
%34 = icmp eq i64 %33, %11
br i1 %34, label %35, label %12
35: ; preds = %26, %2
%36 = phi i8* [ %7, %2 ], [ %28, %26 ]
%37 = phi i8* [ %8, %2 ], [ %29, %26 ]
%38 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @strlen(i8* %36)
%40 = call i32 @strlen(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @strlen(i8* %37)
%42 = add i32 %38, 3
%43 = add i32 %42, %39
%44 = add i32 %43, %40
%45 = add i32 %44, %41
%46 = call i8* @malloc_string(i32 %45)
%47 = call i32 @sprintf(i8* dereferenceable(1) %46, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%48 = call i32 @free(i8* %36)
%49 = call i32 @free(i8* %37)
ret i8* %46
}