#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  char comando[50];
  strcpy(comando, argv[1]);
  if (argc == 2)
    system(comando);
  else {
    strcat(comando, " > ");
    strcat(comando, argv[2]);
    system(comando);
    FILE *arq;
    arq = fopen(argv[2], "r");
    char ch;
    while ((ch = fgetc(arq)) != EOF)
      putchar(ch);
    fclose(arq);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
cmpl   $0x2,-0x8(%rbp)
jne    11af <main+0x3f>
lea    -0x50(%rbp),%rdi
call   1060 <system@plt>
jmp    1229 <main+0xb9>
lea    -0x50(%rbp),%rdi
lea    0xe46(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <strcat@plt>
lea    -0x50(%rbp),%rdi
call   1060 <system@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x59(%rbp)
movsbl %al,%eax
mov    0x2de1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1220 <main+0xb0>
movsbl -0x59(%rbp),%edi
call   1030 <putchar@plt>
jmp    11f1 <main+0x81>
mov    -0x58(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rsi
mov    %rsp,%rdi
call   1040 <strcpy@plt>
cmp    $0x2,%ebp
jne    1196 <main+0x26>
mov    %rsp,%rdi
call   1060 <system@plt>
jmp    120d <main+0x9d>
lea    0xe63(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1090 <strcat@plt>
mov    0x10(%rbx),%rsi
mov    %rbp,%rdi
call   1090 <strcat@plt>
mov    %rbp,%rdi
call   1060 <system@plt>
mov    0x10(%rbx),%rdi
lea    0xe3d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    0x2e0a(%rip),%rbp
cmp    0x0(%rbp),%al
je     1205 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    0x0(%rbp),%al
jne    11f0 <main+0x80>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" > \00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [50 x i8]
%7 = alloca i32*
%8 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strcpy(i8* %9, i8* %12)
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%18 = call i32 @system(i8* %17)
br label %46
19: ; preds = %2
%20 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%21 = call i32 @strcat(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @strcat(i8* %22, i8* %25)
%27 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%28 = call i32 @system(i8* %27)
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %7
br label %33
33: ; preds = %40, %19
%34 = load i32*, i32** %7
%35 = call signext i8 @fgetc(i32* %34)
store i8 %35, i8* %8
%36 = sext i8 %35 to i32
%37 = load i8, i8* @EOF
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %36, %38
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = load i8, i8* %8
%42 = call i32 @putchar(i8 signext %41)
br label %33
43: ; preds = %33
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
br label %46
46: ; preds = %43, %16
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c" > \00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [50 x i8]
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = call i32 @strcpy(i8* %4, i8* %6)
%8 = icmp eq i32 %0, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @system(i8* %4)
br label %30
11: ; preds = %2
%12 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = call i32 @strcat(i8* %4, i8* %14)
%16 = call i32 @system(i8* %4)
%17 = load i8*, i8** %13
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = call signext i8 @fgetc(i32* %18)
%20 = load i8, i8* @EOF
%21 = icmp eq i8 %19, %20
br i1 %21, label %28, label %22
22: ; preds = %11, %22
%23 = phi i8 [ %25, %22 ], [ %19, %11 ]
%24 = call i32 @putchar(i8 signext %23)
%25 = call signext i8 @fgetc(i32* %18)
%26 = load i8, i8* @EOF
%27 = icmp eq i8 %25, %26
br i1 %27, label %28, label %22
28: ; preds = %22, %11
%29 = call i32 @fclose(i32* %18)
br label %30
30: ; preds = %28, %9
ret i32 0
}