#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 WEXITSTATUS(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int system(char *);
int main(int argc, char *argv[]) {
  int rv;
  if (argc < 2)
    return -1;
  rv = system(argv[1]);
  if (rv < 0) {
    fprintf(stderr, "Error calling system(): %d\n", errno);
    return 1;
  }
  printf("Done!\n");
  if (WEXITSTATUS(rv) != 0) {
    fprintf(stderr, "Command returned non-zero exit code: %d\n",
            WEXITSTATUS(rv));
    return 1;
  }
  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)
cmpl   $0x2,-0x8(%rbp)
jge    116c <main+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <system@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b0 <main+0x70>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
lea    0xe61(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1205 <main+0xc5>
lea    0xe65(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
cmp    $0x0,%eax
je     11fe <main+0xbe>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%edx
lea    0xe36(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1205 <main+0xc5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffff,%eax
cmp    $0x2,%edi
jl     11b7 <main+0x77>
mov    0x8(%rsi),%rdi
call   1040 <system@plt>
test   %eax,%eax
js     1190 <main+0x50>
mov    %eax,%ebx
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
call   1060 <WEXITSTATUS@plt>
test   %eax,%eax
je     11b5 <main+0x75>
mov    0x2e66(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1060 <WEXITSTATUS@plt>
lea    0xe92(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
jmp    11a9 <main+0x69>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
lea    0xe57(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    11b7 <main+0x77>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Error calling system(): %d\0A\00"
@errno = global i32 0
@.str.1 = [7 x i8] c"Done!\0A\00"
@.str.2 = [41 x i8] c"Command returned non-zero exit code: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %32
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @system(i8* %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i32, i32* @stderr
%19 = load i32, i32* @errno
%20 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %19)
store i32 1, i32* %3
br label %32
21: ; preds = %10
%22 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* %6
%24 = call i32 @WEXITSTATUS(i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i32, i32* %6
%29 = call i32 @WEXITSTATUS(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %29)
store i32 1, i32* %3
br label %32
31: ; preds = %21
store i32 0, i32* %3
br label %32
32: ; preds = %31, %26, %17, %9
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Error calling system(): %d\0A\00"
@errno = global i32 0
@.str.2 = [41 x i8] c"Command returned non-zero exit code: %d\0A\00"
@str = [6 x i8] c"Done!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %21, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @system(i8* %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %21
13: ; preds = %4
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @WEXITSTATUS(i32 %7)
%16 = icmp eq i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = tail call i32 @WEXITSTATUS(i32 %7)
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %19)
br label %21
21: ; preds = %13, %2, %17, %9
%22 = phi i32 [ 1, %9 ], [ 1, %17 ], [ -1, %2 ], [ 0, %13 ]
ret i32 %22
}