#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 *search_replace_string(char *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *build_sys_str(char *sys_str, int *trace_mode, int argc, char **argv,
                    char *replace_buffer) {
  int i, str_len;
  char *parameter;
  i = 1;
  if (strcmp(argv[1], "-t") == 0) {
    *trace_mode = 1;
    i++;
  } else
    *trace_mode = 0;
  strcpy(sys_str, argv[i]);
  while (++i <= argc - 1) {
    parameter = argv[i];
    str_len = strlen(sys_str);
    if (strlen(parameter) + str_len + 1 > 4096) {
      return (char *)0;
    }
    sprintf(sys_str + strlen(sys_str), " %s", parameter);
  }
  return search_replace_string(sys_str, "{}", replace_buffer);
}


x86 assembly (clang, -O0):
<build_sys_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11a8 <build_sys_str+0x58>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11b2 <build_sys_str+0x62>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1250 <build_sys_str+0x100>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <strlen@plt>
add    -0x38(%rbp),%eax
add    $0x1,%eax
cmp    $0x1000,%eax
jle    1221 <build_sys_str+0xd1>
movq   $0x0,-0x8(%rbp)
jmp    1268 <build_sys_str+0x118>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x40(%rbp),%rdx
lea    0xdbd(%rip),%rsi
call   1070 <sprintf@plt>
jmp    11c7 <build_sys_str+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xda8(%rip),%rsi
call   1050 <search_replace_string@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_sys_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,(%rsp)
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rsi,%r12
mov    %rdi,%r13
mov    0x8(%rcx),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <strcmp@plt>
xor    %r14d,%r14d
test   %rax,%rax
sete   %r14b
mov    %r14d,(%r12)
add    $0x1,%r14d
mov    (%r15,%r14,8),%rsi
mov    %r13,%rdi
call   1030 <strcpy@plt>
add    $0xffffffff,%ebp
cmp    %ebp,%r14d
jge    11f6 <build_sys_str+0xa6>
mov    %ebp,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%r15,%r14,8),%rbp
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
cmp    $0xfff,%eax
jg     1217 <build_sys_str+0xc7>
add    $0x1,%r14
mov    %r13,%rdi
call   1040 <strlen@plt>
movslq %eax,%rdi
add    %r13,%rdi
lea    0xe1a(%rip),%rsi
mov    %rbp,%rdx
call   1070 <sprintf@plt>
cmp    %r14,%r12
jne    11b0 <build_sys_str+0x60>
lea    0xe0a(%rip),%rsi
mov    %r13,%rdi
mov    (%rsp),%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <search_replace_string@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"-t\00"
@.str.1 = [4 x i8] c" %s\00"
@.str.2 = [3 x i8] c"{}\00"
define i8* @build_sys_str(i8* %0, i32* nocapture writeonly %1, i32 %2, i8** nocapture %3, i8* %4) {
%6 = getelementptr inbounds i8*, i8** %3, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = select i1 %9, i32 2, i32 1
store i32 %10, i32* %1
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8*, i8** %3, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 @strcpy(i8* %0, i8* %14)
%16 = add i32 %2, -1
%17 = icmp slt i32 %11, %16
br i1 %17, label %18, label %35
18: ; preds = %5
%19 = zext i32 %16 to i64
br label %20
20: ; preds = %18, %29
%21 = phi i64 [ %12, %18 ], [ %22, %29 ]
%22 = add nuw nsw i64 %21, 1
%23 = getelementptr inbounds i8*, i8** %3, i64 %22
%24 = load i8*, i8** %23
%25 = tail call i32 @strlen(i8* %0)
%26 = tail call i32 @strlen(i8* %24)
%27 = add nsw i32 %26, %25
%28 = icmp sgt i32 %27, 4095
br i1 %28, label %37, label %29
29: ; preds = %20
%30 = tail call i32 @strlen(i8* %0)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %0, i64 %31
%33 = tail call i32 @sprintf(i8* dereferenceable(1) %32, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%34 = icmp eq i64 %22, %19
br i1 %34, label %35, label %20
35: ; preds = %29, %5
%36 = tail call i8* @search_replace_string(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %37
37: ; preds = %20, %35
%38 = phi i8* [ %36, %35 ], [ null, %20 ]
ret i8* %38
}