#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*/ basename(char *);
scalar_t__ check_cmd(int, char **, char *);
int /*<<< orphan*/ cmd_file_read(int, char **);
int /*<<< orphan*/ cmd_file_write(int, char **);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *);
scalar_t__ strncmp(int /*<<< orphan*/, char *, int);
int main(int argc, char **argv) {
  if (argc == 1) {
    if (strncmp(basename(argv[0]), "file_utils", sizeof("file_utils")) == 0) {
      print_usage();
      return 0;
    }
  }
  if (check_cmd(argc, argv, "file_read") == 0) {
    printf("File Read.\n");
    cmd_file_read(argc, argv);
    return 0;
  }
  if (check_cmd(argc, argv, "file_write") == 0) {
    printf("File Write.\n");
    cmd_file_write(argc, argv);
    return 0;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11d1 <main+0x61>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <basename@plt>
mov    %eax,%edi
lea    0xe5b(%rip),%rsi
mov    $0xb,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11cc <main+0x5c>
mov    $0x0,%al
call   1090 <print_usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    125a <main+0xea>
jmp    11d1 <main+0x61>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe2c(%rip),%rdx
call   1070 <check_cmd@plt>
cmp    $0x0,%rax
jne    1212 <main+0xa2>
lea    0xe20(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <cmd_file_read@plt>
movl   $0x0,-0x4(%rbp)
jmp    125a <main+0xea>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe01(%rip),%rdx
call   1070 <check_cmd@plt>
cmp    $0x0,%rax
jne    1253 <main+0xe3>
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <cmd_file_write@plt>
movl   $0x0,-0x4(%rbp)
jmp    125a <main+0xea>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x1,%edi
jne    119d <main+0x2d>
mov    (%rbx),%rdi
call   1050 <basename@plt>
lea    0xe74(%rip),%rsi
mov    %eax,%edi
mov    $0xb,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11f9 <main+0x89>
lea    0xe67(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <check_cmd@plt>
test   %rax,%rax
je     11e1 <main+0x71>
lea    0xe5b(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <check_cmd@plt>
test   %rax,%rax
jne    1200 <main+0x90>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <cmd_file_write@plt>
jmp    1200 <main+0x90>
lea    0xe44(%rip),%rdi
call   1040 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1080 <cmd_file_read@plt>
jmp    1200 <main+0x90>
xor    %eax,%eax
call   1090 <print_usage@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"file_utils\00"
@.str.1 = [10 x i8] c"file_read\00"
@.str.2 = [12 x i8] c"File Read.\0A\00"
@.str.3 = [11 x i8] c"file_write\00"
@.str.4 = [13 x i8] c"File Write.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = call i32 @basename(i8* %11)
%13 = call i64 @strncmp(i32 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 11)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = call i32 (...) @print_usage()
store i32 0, i32* %3
br label %39
17: ; preds = %8
br label %18
18: ; preds = %17, %2
%19 = load i32, i32* %4
%20 = load i8**, i8*** %5
%21 = call i64 @check_cmd(i32 %19, i8** %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* %4
%26 = load i8**, i8*** %5
%27 = call i32 @cmd_file_read(i32 %25, i8** %26)
store i32 0, i32* %3
br label %39
28: ; preds = %18
%29 = load i32, i32* %4
%30 = load i8**, i8*** %5
%31 = call i64 @check_cmd(i32 %29, i8** %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%35 = load i32, i32* %4
%36 = load i8**, i8*** %5
%37 = call i32 @cmd_file_write(i32 %35, i8** %36)
store i32 0, i32* %3
br label %39
38: ; preds = %28
store i32 0, i32* %3
br label %39
39: ; preds = %38, %33, %23, %15
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [11 x i8] c"file_utils\00"
@.str.1 = [10 x i8] c"file_read\00"
@.str.3 = [11 x i8] c"file_write\00"
@str = [12 x i8] c"File Write.\00"
@str.5 = [11 x i8] c"File Read.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @basename(i8* %5)
%7 = tail call i64 @strncmp(i32 %6, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 11)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 (...) @print_usage()
br label %23
11: ; preds = %4, %2
%12 = tail call i64 @check_cmd(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
%16 = tail call i32 @cmd_file_read(i32 %0, i8** %1)
br label %23
17: ; preds = %11
%18 = tail call i64 @check_cmd(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%22 = tail call i32 @cmd_file_write(i32 %0, i8** %1)
br label %23
23: ; preds = %17, %20, %14, %9
ret i32 0
}