#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
void log_start_args(int argc, char **argv) {
  char *cmdline;
  int cmdline_len = 0;
  int i;
  for (i = 0; i < argc; ++i) {
    cmdline_len += strlen(argv[i]) + 1;
  }
  cmdline = malloc(cmdline_len + 1);
  cmdline[0] = '\0';
  for (i = 0; i < argc; ++i) {
    strcat(cmdline, argv[i]);
    strcat(cmdline, " ");
  }
  do {
  } while ((!(1 == 1)));
  free(cmdline);
}


x86 assembly (clang, -O0):
<log_start_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1199 <log_start_args+0x59>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115d <log_start_args+0x1d>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11f5 <log_start_args+0xb5>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1060 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b6 <log_start_args+0x76>
jmp    11fa <log_start_args+0xba>
jmp    11ff <log_start_args+0xbf>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_start_args>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
jle    11c2 <log_start_args+0x82>
mov    %rsi,%r15
mov    %edi,%r14d
mov    %edi,%r12d
xor    %ebx,%ebx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%rdi
call   1040 <strlen@plt>
add    %eax,%ebp
add    $0x1,%ebp
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <log_start_args+0x20>
add    $0x1,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
movb   $0x0,(%rax)
test   %r14d,%r14d
jle    11d2 <log_start_args+0x92>
xor    %ebx,%ebx
lea    0xe6b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%rbx,8),%rsi
mov    %rbp,%rdi
call   1060 <strcat@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11a0 <log_start_args+0x60>
jmp    11d2 <log_start_args+0x92>
mov    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %rbp,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

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