#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*/ err(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, scalar_t__);
int /*<<< orphan*/ strncpy(char *, char *, int);
void fill_cmd(char **cmdv, char *path, char *buff, int n) {
  int i;
  char *tempbuff = malloc(n);
  ;
  if (tempbuff == NULL)
    err(1, NULL);
  strncpy(tempbuff, cmdv[0], n);
  for (i = 1; cmdv[i]; i++) {
    strncat(tempbuff, " ", n - strlen(tempbuff));
    strncat(tempbuff, cmdv[i], n - strlen(tempbuff));
  }
  strncat(tempbuff, " ", n - strlen(tempbuff));
  snprintf(buff, n, tempbuff, path);
  free(tempbuff);
}


x86 assembly (clang, -O0):
<fill_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ac <fill_cmd+0x3c>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <err@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <strncpy@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1254 <fill_cmd+0xe4>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
movslq -0x1c(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x50(%rbp),%rdx
mov    -0x48(%rbp),%rdi
sub    %rax,%rdx
lea    0xdfc(%rip),%rsi
call   1070 <strncat@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
movslq -0x1c(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
sub    %rax,%rdx
call   1070 <strncat@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c6 <fill_cmd+0x56>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
movslq -0x1c(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%rdi
sub    %rax,%rdx
lea    0xd81(%rip),%rsi
call   1070 <strncat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   1060 <snprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_cmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rdx,0x8(%rsp)
mov    %rsi,0x10(%rsp)
mov    %rdi,%rbp
mov    %ecx,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a9 <fill_cmd+0x39>
mov    $0x1,%edi
xor    %esi,%esi
call   1080 <err@plt>
mov    0x0(%rbp),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
call   1040 <strncpy@plt>
cmpq   $0x0,0x8(%rbp)
movslq %r12d,%r13
je     1211 <fill_cmd+0xa1>
add    $0x10,%rbp
lea    0xe33(%rip),%r14
nopl   (%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdx
sub    %rax,%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strncat@plt>
mov    -0x8(%rbp),%r15
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r13,%rdx
sub    %rax,%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strncat@plt>
cmpq   $0x0,0x0(%rbp)
lea    0x8(%rbp),%rbp
jne    11d0 <fill_cmd+0x60>
mov    %rbx,%rdi
call   1050 <strlen@plt>
sub    %rax,%r13
lea    0xddd(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
call   1070 <strncat@plt>
mov    0x8(%rsp),%rdi
mov    %r12d,%esi
mov    %rbx,%rdx
mov    0x10(%rsp),%rcx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
define void @fill_cmd(i8** %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %10
%13 = load i8*, i8** %10
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = call i32 @err(i32 1, i32* null)
br label %17
17: ; preds = %15, %4
%18 = load i8*, i8** %10
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = load i32, i32* %8
%23 = call i32 @strncpy(i8* %18, i8* %21, i32 %22)
store i32 1, i32* %9
br label %24
24: ; preds = %51, %17
%25 = load i8**, i8*** %5
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %54
31: ; preds = %24
%32 = load i8*, i8** %10
%33 = load i32, i32* %8
%34 = sext i32 %33 to i64
%35 = load i8*, i8** %10
%36 = call i64 @strlen(i8* %35)
%37 = sub nsw i64 %34, %36
%38 = call i32 @strncat(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 %37)
%39 = load i8*, i8** %10
%40 = load i8**, i8*** %5
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = load i8*, i8** %10
%48 = call i64 @strlen(i8* %47)
%49 = sub nsw i64 %46, %48
%50 = call i32 @strncat(i8* %39, i8* %44, i64 %49)
br label %51
51: ; preds = %31
%52 = load i32, i32* %9
%53 = add nsw i32 %52, 1
store i32 %53, i32* %9
br label %24
54: ; preds = %24
%55 = load i8*, i8** %10
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = load i8*, i8** %10
%59 = call i64 @strlen(i8* %58)
%60 = sub nsw i64 %57, %59
%61 = call i32 @strncat(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 %60)
%62 = load i8*, i8** %7
%63 = load i32, i32* %8
%64 = load i8*, i8** %10
%65 = load i8*, i8** %6
%66 = call i32 @snprintf(i8* %62, i32 %63, i8* %64, i8* %65)
%67 = load i8*, i8** %10
%68 = call i32 @free(i8* %67)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
define void @fill_cmd(i8** nocapture %0, i8* %1, i8* %2, i32 %3) {
%5 = tail call i8* @malloc(i32 %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @err(i32 1, i32* null)
br label %9
9: ; preds = %7, %4
%10 = load i8*, i8** %0
%11 = tail call i32 @strncpy(i8* %5, i8* %10, i32 %3)
%12 = getelementptr inbounds i8*, i8** %0, i64 1
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
%15 = sext i32 %3 to i64
br i1 %14, label %30, label %16
16: ; preds = %9, %16
%17 = phi i64 [ %26, %16 ], [ 1, %9 ]
%18 = phi i8** [ %27, %16 ], [ %12, %9 ]
%19 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%20 = sub nsw i64 %15, %19
%21 = tail call i32 @strncat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 %20)
%22 = load i8*, i8** %18
%23 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%24 = sub nsw i64 %15, %23
%25 = tail call i32 @strncat(i8* %5, i8* %22, i64 %24)
%26 = add nuw i64 %17, 1
%27 = getelementptr inbounds i8*, i8** %0, i64 %26
%28 = load i8*, i8** %27
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %16
30: ; preds = %16, %9
%31 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%32 = sub nsw i64 %15, %31
%33 = tail call i32 @strncat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i64 %32)
%34 = tail call i32 @snprintf(i8* %2, i32 %3, i8* %5, i8* %1)
%35 = tail call i32 @free(i8* %5)
ret void
}