#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 */
scalar_t__ asprintf(char **, char *, char *, char *);
int /*<<< orphan*/ free(char *);
char *strdup(char *);
int util_argstr(char **av, char **strp) {
  char *str = NULL;
  char *old;
  int res = 0;
  while (*av != NULL) {
    if (str == NULL) {
      str = strdup(*av);
      if (!str) {
        res = 14;
        goto done;
      }
    } else {
      old = str;
      if (asprintf(&str, "%s %s", old, *av) < 0) {
        res = 14;
        free(old);
        goto done;
      }
      free(old);
    }
    av++;
  }
done:
  if (strp && res == 0)
    *strp = str;
  return res;
}


x86 assembly (clang, -O0):
<util_argstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11f0 <util_argstr+0xc0>
cmpq   $0x0,-0x18(%rbp)
jne    1194 <util_argstr+0x64>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118f <util_argstr+0x5f>
movl   $0xe,-0x24(%rbp)
jmp    11f5 <util_argstr+0xc5>
jmp    11df <util_argstr+0xaf>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
lea    -0x18(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1040 <asprintf@plt>
cmp    $0x0,%rax
jge    11d6 <util_argstr+0xa6>
movl   $0xe,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    11f5 <util_argstr+0xc5>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x8(%rbp)
jmp    114f <util_argstr+0x1f>
jmp    11f5 <util_argstr+0xc5>
cmpq   $0x0,-0x10(%rbp)
je     1215 <util_argstr+0xe5>
cmpl   $0x0,-0x24(%rbp)
jne    1215 <util_argstr+0xe5>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_argstr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
movq   $0x0,(%rsp)
mov    (%rdi),%rcx
test   %rcx,%rcx
je     11b9 <util_argstr+0x89>
mov    %rdi,%r13
add    $0x8,%r13
xor    %ebx,%ebx
lea    0xea2(%rip),%r15
mov    %rsp,%r12
test   %rbx,%rbx
je     1190 <util_argstr+0x60>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <asprintf@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %rbp,%rbp
jns    11a1 <util_argstr+0x71>
jmp    11c9 <util_argstr+0x99>
mov    %rcx,%rdi
call   1050 <strdup@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     11c9 <util_argstr+0x99>
mov    0x0(%r13),%rcx
test   %rcx,%rcx
je     11b9 <util_argstr+0x89>
mov    (%rsp),%rbx
add    $0x8,%r13
test   %rbx,%rbx
jne    1170 <util_argstr+0x40>
jmp    1190 <util_argstr+0x60>
xor    %eax,%eax
test   %r14,%r14
je     11ce <util_argstr+0x9e>
mov    (%rsp),%rcx
mov    %rcx,(%r14)
jmp    11ce <util_argstr+0x9e>
mov    $0xe,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s %s\00"
define i32 @util_argstr(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8** %0, i8*** %3
store i8** %1, i8*** %4
store i8* null, i8** %5
store i32 0, i32* %7
br label %8
8: ; preds = %36, %2
%9 = load i8**, i8*** %3
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %39
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i8**, i8*** %3
%17 = load i8*, i8** %16
%18 = call i8* @strdup(i8* %17)
store i8* %18, i8** %5
%19 = load i8*, i8** %5
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %15
store i32 14, i32* %7
br label %40
22: ; preds = %15
br label %36
23: ; preds = %12
%24 = load i8*, i8** %5
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = load i8**, i8*** %3
%27 = load i8*, i8** %26
%28 = call i64 @asprintf(i8** %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %25, i8* %27)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %23
store i32 14, i32* %7
%31 = load i8*, i8** %6
%32 = call i32 @free(i8* %31)
br label %40
33: ; preds = %23
%34 = load i8*, i8** %6
%35 = call i32 @free(i8* %34)
br label %36
36: ; preds = %33, %22
%37 = load i8**, i8*** %3
%38 = getelementptr inbounds i8*, i8** %37, i32 1
store i8** %38, i8*** %3
br label %8
39: ; preds = %8
br label %40
40: ; preds = %39, %30, %21
%41 = load i8**, i8*** %4
%42 = icmp ne i8** %41, null
br i1 %42, label %43, label %49
43: ; preds = %40
%44 = load i32, i32* %7
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i8*, i8** %5
%48 = load i8**, i8*** %4
store i8* %47, i8** %48
br label %49
49: ; preds = %46, %43, %40
%50 = load i32, i32* %7
ret i32 %50
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s %s\00"
define i32 @util_argstr(i8** nocapture %0, i8** writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = load i8*, i8** %0
%6 = icmp eq i8* %5, null
br i1 %6, label %25, label %7
7: ; preds = %2, %23
%8 = phi i8* [ %24, %23 ], [ null, %2 ]
%9 = phi i8* [ %21, %23 ], [ %5, %2 ]
%10 = phi i8** [ %20, %23 ], [ %0, %2 ]
%11 = icmp eq i8* %8, null
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = call i8* @strdup(i8* %9)
store i8* %13, i8** %3
%14 = icmp eq i8* %13, null
br i1 %14, label %29, label %19
15: ; preds = %7
%16 = call i64 @asprintf(i8** %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %9)
%17 = icmp slt i64 %16, 0
%18 = call i32 @free(i8* %8)
br i1 %17, label %29, label %19
19: ; preds = %15, %12
%20 = getelementptr inbounds i8*, i8** %10, i64 1
%21 = load i8*, i8** %20
%22 = icmp eq i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = load i8*, i8** %3
br label %7
25: ; preds = %19, %2
%26 = icmp eq i8** %1, null
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = load i8*, i8** %3
store i8* %28, i8** %1
br label %29
29: ; preds = %12, %15, %27, %25
%30 = phi i32 [ 0, %27 ], [ 0, %25 ], [ 14, %15 ], [ 14, %12 ]
ret i32 %30
}