#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*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int system(char *);
int co_sh(int argc, char *argv[]) {
  int retval;
  int i;
  char commandline[1024];
  if (argc <= 1)
    strcpy(commandline, "sh");
  else {
    strcpy(commandline, "");
    for (i = 1; i < argc; i++) {
      if (i > 1)
        strcat(commandline, " ");
      strcat(commandline, argv[i]);
    }
  }
  retval = system(commandline);
  return (retval);
}


x86 assembly (clang, -O0):
<co_sh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jg     1164 <co_sh+0x34>
lea    -0x420(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11d2 <co_sh+0xa2>
lea    -0x420(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11cd <co_sh+0x9d>
cmpl   $0x1,-0x18(%rbp)
jle    11a7 <co_sh+0x77>
lea    -0x420(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1050 <strcat@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    117e <co_sh+0x4e>
jmp    11d2 <co_sh+0xa2>
lea    -0x420(%rbp),%rdi
call   1040 <system@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<co_sh>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
cmp    $0x1,%edi
jg     1155 <co_sh+0x25>
lea    0xeb5(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
jmp    11b0 <co_sh+0x80>
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xea3(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    0x8(%r15),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
cmp    $0x2,%ebp
je     11b0 <co_sh+0x80>
mov    %ebp,%r12d
mov    $0x2,%ebx
lea    0xe77(%rip),%r14
mov    %rsp,%rbp
nop
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
mov    (%r15,%rbx,8),%rsi
mov    %rbp,%rdi
call   1050 <strcat@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1190 <co_sh+0x60>
mov    %rsp,%rdi
call   1040 <system@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"sh\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c" \00"
define i32 @co_sh(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1024 x i8]
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%12 = call i32 @strcpy(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %38
13: ; preds = %2
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %6
br label %16
16: ; preds = %34, %13
%17 = load i32, i32* %6
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %37
20: ; preds = %16
%21 = load i32, i32* %6
%22 = icmp sgt i32 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %23, %20
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%28 = load i8**, i8*** %4
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8*, i8** %28, i64 %30
%32 = load i8*, i8** %31
%33 = call i32 @strcat(i8* %27, i8* %32)
br label %34
34: ; preds = %26
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %16
37: ; preds = %16
br label %38
38: ; preds = %37, %10
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%40 = call i32 @system(i8* %39)
store i32 %40, i32* %5
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"sh\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c" \00"
define i32 @co_sh(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %23
8: ; preds = %2
%9 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%10 = zext i32 %0 to i64
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strcat(i8* %4, i8* %12)
%14 = icmp eq i32 %0, 2
br i1 %14, label %23, label %15
15: ; preds = %8, %15
%16 = phi i64 [ %21, %15 ], [ 2, %8 ]
%17 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = getelementptr inbounds i8*, i8** %1, i64 %16
%19 = load i8*, i8** %18
%20 = call i32 @strcat(i8* %4, i8* %19)
%21 = add nuw nsw i64 %16, 1
%22 = icmp eq i64 %21, %10
br i1 %22, label %23, label %15
23: ; preds = %15, %8, %6
%24 = call i32 @system(i8* %4)
ret i32 %24
}