#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 SYSTEM(char *);
int errno;
int /*<<< orphan*/ pr_exit(int);
int /*<<< orphan*/ printf(char *, int, ...);
int main(int argc, char *argv[]) {
  int ret = 0;
  ret = SYSTEM(0);
  printf("system return %d\n", ret);
  ret = SYSTEM("date > date.log");
  printf("system return %d, errno = %d\n", ret, errno);
  pr_exit(ret);
  ret = SYSTEM("top");
  printf("system return %d, errno = %d\n", ret, errno);
  pr_exit(ret);
  ret = SYSTEM("nosuchcommand");
  printf("system return %d, errno = %d\n", ret, errno);
  pr_exit(ret);
  ret = SYSTEM("who; exit 44");
  printf("system return %d, errno = %d\n", ret, errno);
  pr_exit(ret);
  if (argc > 1) {
    ret = SYSTEM(argv[1]);
    printf("system return %d, errno = %d\n", ret, errno);
    pr_exit(ret);
  }
  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   $0x0,-0x14(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <SYSTEM@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea1(%rip),%rdi
call   1030 <SYSTEM@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <pr_exit@plt>
lea    0xe9e(%rip),%rdi
call   1030 <SYSTEM@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <pr_exit@plt>
lea    0xe71(%rip),%rdi
call   1030 <SYSTEM@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    0x2dfb(%rip),%rax
mov    (%rax),%edx
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <pr_exit@plt>
lea    0xe4e(%rip),%rdi
call   1030 <SYSTEM@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    0x2dca(%rip),%rax
mov    (%rax),%edx
lea    0xe03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <pr_exit@plt>
cmpl   $0x1,-0x8(%rbp)
jle    126a <main+0x13a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <SYSTEM@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
mov    0x2d8e(%rip),%rax
mov    (%rax),%edx
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %edi,%r15d
xor    %edi,%edi
call   1030 <SYSTEM@plt>
lea    0xeb4(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeb6(%rip),%rdi
call   1030 <SYSTEM@plt>
mov    %eax,%ebp
mov    0x2e76(%rip),%r12
mov    (%r12),%edx
lea    0xead(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <pr_exit@plt>
lea    0xeb1(%rip),%rdi
call   1030 <SYSTEM@plt>
mov    %eax,%ebp
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <pr_exit@plt>
lea    0xe90(%rip),%rdi
call   1030 <SYSTEM@plt>
mov    %eax,%ebp
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <pr_exit@plt>
lea    0xe79(%rip),%rdi
call   1030 <SYSTEM@plt>
mov    %eax,%ebp
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <pr_exit@plt>
cmp    $0x2,%r15d
jl     1223 <main+0xf3>
mov    0x8(%r14),%rdi
call   1030 <SYSTEM@plt>
mov    %eax,%ebx
mov    (%r12),%edx
lea    0xe0f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <pr_exit@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"system return %d\0A\00"
@.str.1 = [16 x i8] c"date > date.log\00"
@.str.2 = [30 x i8] c"system return %d, errno = %d\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"top\00"
@.str.4 = [14 x i8] c"nosuchcommand\00"
@.str.5 = [13 x i8] c"who; exit 44\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
store i32 0, i32* %6
%7 = call i32 @SYSTEM(i8* null)
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @SYSTEM(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = load i32, i32* @errno
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %12)
%14 = load i32, i32* %6
%15 = call i32 @pr_exit(i32 %14)
%16 = call i32 @SYSTEM(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = load i32, i32* @errno
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
%20 = load i32, i32* %6
%21 = call i32 @pr_exit(i32 %20)
%22 = call i32 @SYSTEM(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = load i32, i32* @errno
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32, i32* %6
%27 = call i32 @pr_exit(i32 %26)
%28 = call i32 @SYSTEM(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = load i32, i32* @errno
%31 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %30)
%32 = load i32, i32* %6
%33 = call i32 @pr_exit(i32 %32)
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 1
br i1 %35, label %36, label %46
36: ; preds = %2
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i32 @SYSTEM(i8* %39)
store i32 %40, i32* %6
%41 = load i32, i32* %6
%42 = load i32, i32* @errno
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %42)
%44 = load i32, i32* %6
%45 = call i32 @pr_exit(i32 %44)
br label %46
46: ; preds = %36, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"system return %d\0A\00"
@.str.1 = [16 x i8] c"date > date.log\00"
@.str.2 = [30 x i8] c"system return %d, errno = %d\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"top\00"
@.str.4 = [14 x i8] c"nosuchcommand\00"
@.str.5 = [13 x i8] c"who; exit 44\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32 @SYSTEM(i8* null)
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @SYSTEM(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* @errno
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %6)
%8 = tail call i32 @pr_exit(i32 %5)
%9 = tail call i32 @SYSTEM(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%10 = load i32, i32* @errno
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %9, i32 %10)
%12 = tail call i32 @pr_exit(i32 %9)
%13 = tail call i32 @SYSTEM(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%14 = load i32, i32* @errno
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %14)
%16 = tail call i32 @pr_exit(i32 %13)
%17 = tail call i32 @SYSTEM(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%18 = load i32, i32* @errno
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %18)
%20 = tail call i32 @pr_exit(i32 %17)
%21 = icmp sgt i32 %0, 1
br i1 %21, label %22, label %29
22: ; preds = %2
%23 = getelementptr inbounds i8*, i8** %1, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @SYSTEM(i8* %24)
%26 = load i32, i32* @errno
%27 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %26)
%28 = tail call i32 @pr_exit(i32 %25)
br label %29
29: ; preds = %22, %2
ret i32 0
}