#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*/ catfiles(char *, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  char a[100] = {0};
  if (argc >= 2) {
    strcpy(a, argv[1]);
  } else {
    strcpy(a, "/rootfs/etc/help");
  }
  int flag;
  if (argc >= 3) {
    if (strcmp(argv[2], "wr_pipe") == 0)
      flag = 1;
    else if (strcmp(argv[2], "rd_pipe") == 0)
      flag = 2;
    else
      flag = 0;
  } else {
    flag = 0;
  }
  catfiles(a, flag);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
jl     1189 <main+0x49>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
jmp    1199 <main+0x59>
lea    -0x80(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x3,-0x8(%rbp)
jl     1211 <main+0xd1>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe5f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d0 <main+0x90>
movl   $0x1,-0x84(%rbp)
jmp    120c <main+0xcc>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe3a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11fd <main+0xbd>
movl   $0x2,-0x84(%rbp)
jmp    1207 <main+0xc7>
movl   $0x0,-0x84(%rbp)
jmp    120c <main+0xcc>
jmp    121b <main+0xdb>
movl   $0x0,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x84(%rbp),%esi
call   1060 <catfiles@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x68,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
cmp    $0x1,%edi
jle    11ad <main+0x7d>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
xor    %esi,%esi
cmp    $0x2,%ebp
je     11be <main+0x8e>
mov    0x10(%rbx),%rdi
lea    0xe8b(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11cf <main+0x9f>
mov    0x10(%rbx),%rdi
lea    0xe7e(%rip),%rsi
call   1040 <strcmp@plt>
xor    %esi,%esi
test   %rax,%rax
sete   %sil
add    %esi,%esi
jmp    11be <main+0x8e>
lea    0xe4c(%rip),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
xor    %esi,%esi
mov    %rsp,%rdi
call   1050 <catfiles@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret
mov    $0x1,%esi
jmp    11be <main+0x8e>

LLVM IR (-O0):
@.str = [17 x i8] c"/rootfs/etc/help\00"
@.str.1 = [8 x i8] c"wr_pipe\00"
@.str.2 = [8 x i8] c"rd_pipe\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [100 x i8]* %6 to i8*
%9 = load i32, i32* %4
%10 = icmp sge i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strcpy(i8* %12, i8* %15)
br label %20
17: ; preds = %2
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %17, %11
%21 = load i32, i32* %4
%22 = icmp sge i32 %21, 3
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 1, i32* %7
br label %39
30: ; preds = %23
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 2, i32* %7
br label %38
37: ; preds = %30
store i32 0, i32* %7
br label %38
38: ; preds = %37, %36
br label %39
39: ; preds = %38, %29
br label %41
40: ; preds = %20
store i32 0, i32* %7
br label %41
41: ; preds = %40, %39
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%43 = load i32, i32* %7
%44 = call i32 @catfiles(i8* %42, i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"/rootfs/etc/help\00"
@.str.1 = [8 x i8] c"wr_pipe\00"
@.str.2 = [8 x i8] c"rd_pipe\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %23
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @strcpy(i8* %4, i8* %10)
%12 = icmp eq i32 %0, 2
br i1 %12, label %23, label %13
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = load i8*, i8** %14
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i32 2, i32 0
br label %23
23: ; preds = %6, %8, %18, %13
%24 = phi i32 [ 1, %13 ], [ %22, %18 ], [ 0, %8 ], [ 0, %6 ]
%25 = call i32 @catfiles(i8* %4, i32 %24)
ret i32 0
}