#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__ is_num(char *const);
int /*<<< orphan*/ strcat(char *, char *const);
int /*<<< orphan*/ strcpy(char *, char *);
void gen_arg_str(int argc, char *const argv[], int start, char result[]) {
  int i;
  strcpy(result, "");
  if (argc > start) {
    for (i = start; i < argc; i++) {
      strcat(result, " ");
      if ((argv[i][0] == '-') || (is_num(argv[i]) == 0)) {
        strcat(result, argv[i]);
      } else {
        strcat(result, "\"");
        strcat(result, argv[i]);
        strcat(result, "\"");
      }
    }
  }
}


x86 assembly (clang, -O0):
<gen_arg_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    121e <gen_arg_str+0xee>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1219 <gen_arg_str+0xe9>
mov    -0x20(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     11b7 <gen_arg_str+0x87>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <is_num@plt>
cmp    $0x0,%rax
jne    11d1 <gen_arg_str+0xa1>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <strcat@plt>
jmp    1206 <gen_arg_str+0xd6>
mov    -0x20(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   1050 <strcat@plt>
jmp    120b <gen_arg_str+0xdb>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1168 <gen_arg_str+0x38>
jmp    121e <gen_arg_str+0xee>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_arg_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %rsi,%r15
mov    %edi,%r14d
lea    0xeb4(%rip),%rsi
mov    %rcx,%rdi
call   1030 <strcpy@plt>
sub    %ebp,%r14d
jle    11d5 <gen_arg_str+0xa5>
movslq %ebp,%rax
lea    (%r15,%rax,8),%r13
xor    %ebp,%ebp
lea    0xe96(%rip),%r15
lea    0xe91(%rip),%r12
jmp    11ac <gen_arg_str+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
mov    0x0(%r13,%rbp,8),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %r12,%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
add    $0x1,%rbp
cmp    %ebp,%r14d
je     11d5 <gen_arg_str+0xa5>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <strcat@plt>
mov    0x0(%r13,%rbp,8),%rsi
cmpb   $0x2d,(%rsi)
je     119b <gen_arg_str+0x6b>
mov    %rsi,%rdi
call   1040 <is_num@plt>
test   %rax,%rax
jne    1180 <gen_arg_str+0x50>
mov    0x0(%r13,%rbp,8),%rsi
jmp    119b <gen_arg_str+0x6b>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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