#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*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int shell_exec(char *, char **);
int main(int args, char *argv[]) {
  char *c;
  int i = 1;
  for (; i < args; ++i) {
    int rc = shell_exec(argv[i], &c);
    if (rc != 0) {
      perror("shell_exec failed.");
    }
    printf("return:\n%s", c);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11a5 <main+0x75>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <shell_exec@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     1187 <main+0x57>
lea    0xe7e(%rip),%rdi
call   1050 <perror@plt>
mov    -0x18(%rbp),%rsi
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114d <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     1190 <main+0x60>
mov    %rsi,%r13
mov    %edi,%ebx
mov    $0x1,%ebp
mov    %rsp,%r14
lea    0xebf(%rip),%r15
lea    0xea5(%rip),%r12
jmp    1175 <main+0x45>
nopl   (%rax)
mov    (%rsp),%rsi
mov    %r15,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     1190 <main+0x60>
mov    0x0(%r13,%rbp,8),%rdi
mov    %r14,%rsi
call   1040 <shell_exec@plt>
test   %eax,%eax
je     1160 <main+0x30>
mov    %r12,%rdi
call   1050 <perror@plt>
jmp    1160 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"shell_exec failed.\00"
@.str.1 = [11 x i8] c"return:\0A%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
br label %9
9: ; preds = %27, %2
%10 = load i32, i32* %7
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = load i8**, i8*** %5
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8*, i8** %14, i64 %16
%18 = load i8*, i8** %17
%19 = call i32 @shell_exec(i8* %18, i8** %6)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %13
%23 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %13
%25 = load i8*, i8** %6
%26 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %9
30: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"shell_exec failed.\00"
@.str.1 = [11 x i8] c"return:\0A%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp sgt i32 %0, 1
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %16
%9 = phi i64 [ 1, %6 ], [ %19, %16 ]
%10 = getelementptr inbounds i8*, i8** %1, i64 %9
%11 = load i8*, i8** %10
%12 = call i32 @shell_exec(i8* %11, i8** %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %8
%15 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %8
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %21, label %8
21: ; preds = %16, %2
ret i32 0
}