#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 *zbx_malloc(char *, size_t);
int /*<<< orphan*/ zbx_snprintf_alloc(char **, size_t *, size_t *, char *,
                                      char *);
void collect_args(char **argv, int argc, char **args, size_t *args_alloc) {
  int i;
  size_t args_offset = 0;
  if (0 == *args_alloc) {
    *args_alloc = 64;
    *args = zbx_malloc(*args, *args_alloc);
  }
  for (i = 0; i < argc; i++)
    zbx_snprintf_alloc(args, args_alloc, &args_offset, "%s ", argv[i]);
  if (0 != args_offset)
    args_offset--;
  (*args)[args_offset] = '\0';
}


x86 assembly (clang, -O0):
<collect_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
jne    1176 <collect_args+0x56>
mov    -0x20(%rbp),%rax
movq   $0x40,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1030 <zbx_malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11bb <collect_args+0x9b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%r8
lea    -0x30(%rbp),%rdx
lea    0xe58(%rip),%rcx
call   1040 <zbx_snprintf_alloc@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117d <collect_args+0x5d>
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
je     11d3 <collect_args+0xb3>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<collect_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
movq   $0x0,(%rsp)
cmpq   $0x0,(%rcx)
je     1182 <collect_args+0x62>
test   %ebp,%ebp
jle    119d <collect_args+0x7d>
mov    %ebp,%ebp
xor    %r12d,%r12d
mov    %rsp,%r13
mov    (%r15,%r12,8),%r8
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r13,%rdx
lea    0xe9c(%rip),%rcx
call   1040 <zbx_snprintf_alloc@plt>
add    $0x1,%r12
cmp    %r12,%rbp
jne    1150 <collect_args+0x30>
mov    (%rsp),%rcx
xor    %eax,%eax
sub    $0x1,%rcx
cmovae %rcx,%rax
jmp    119f <collect_args+0x7f>
movq   $0x40,(%rbx)
mov    (%r14),%rdi
mov    $0x40,%esi
call   1030 <zbx_malloc@plt>
mov    %rax,(%r14)
test   %ebp,%ebp
jg     1148 <collect_args+0x28>
xor    %eax,%eax
mov    (%r14),%rcx
movb   $0x0,(%rcx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%s \00"
define void @collect_args(i8** nocapture %0, i32 %1, i8** %2, i64* %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%7 = load i64, i64* %3
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
store i64 64, i64* %3
%10 = load i8*, i8** %2
%11 = tail call i8* @zbx_malloc(i8* %10, i64 64)
store i8* %11, i8** %2
br label %12
12: ; preds = %9, %4
%13 = icmp sgt i32 %1, 0
br i1 %13, label %14, label %28
14: ; preds = %12
%15 = zext i32 %1 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 0, %14 ], [ %21, %16 ]
%18 = getelementptr inbounds i8*, i8** %0, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @zbx_snprintf_alloc(i8** %2, i64* %3, i64* %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = add nuw nsw i64 %17, 1
%22 = icmp eq i64 %21, %15
br i1 %22, label %23, label %16
23: ; preds = %16
%24 = load i64, i64* %5
%25 = icmp eq i64 %24, 0
%26 = add i64 %24, -1
%27 = select i1 %25, i64 0, i64 %26
br label %28
28: ; preds = %23, %12
%29 = phi i64 [ 0, %12 ], [ %27, %23 ]
%30 = load i8*, i8** %2
%31 = getelementptr inbounds i8, i8* %30, i64 %29
store i8 0, i8* %31
ret void
}