#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 hdoip_lib_color_format(char *);
int /*<<< orphan*/ hoic_wr(int, int, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
int hdoip_cli_fmt(int fd, int fdr, char **argv, int argc) {
  int fmt = 0;
  if (argc == 2) {
    fmt = hdoip_lib_color_format(argv[1]);
  } else if (argc == 3) {
    fmt = hdoip_lib_color_format(argv[1]);
    fmt |= hdoip_lib_color_format(argv[2]);
  } else {
    printf("too many arguments\n");
    return 0;
  }
  if (fmt == -1) {
    printf("unsupported format\n");
    return 0;
  }
  if (strcmp(argv[0], "in") == 0) {
    hoic_wr(fd, (0x34000007), fmt);
  } else if (strcmp(argv[0], "out") == 0) {
    hoic_wr(fd, (0x34000008), fmt);
  } else if (strcmp(argv[0], "proc") == 0) {
    hoic_wr(fd, (0x34000009), fmt);
  } else {
    printf("unknown direction\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<hdoip_cli_fmt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jne    117b <hdoip_cli_fmt+0x3b>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <hdoip_lib_color_format@plt>
mov    %eax,-0x20(%rbp)
jmp    11ca <hdoip_cli_fmt+0x8a>
cmpl   $0x3,-0x1c(%rbp)
jne    11ad <hdoip_cli_fmt+0x6d>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <hdoip_lib_color_format@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <hdoip_lib_color_format@plt>
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    11c5 <hdoip_cli_fmt+0x85>
lea    0xe4c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129f <hdoip_cli_fmt+0x15f>
jmp    11ca <hdoip_cli_fmt+0x8a>
cmpl   $0xffffffff,-0x20(%rbp)
jne    11ec <hdoip_cli_fmt+0xac>
lea    0xe39(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    129f <hdoip_cli_fmt+0x15f>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe2e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121e <hdoip_cli_fmt+0xde>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%edx
mov    $0x34000007,%esi
call   1030 <hoic_wr@plt>
jmp    1298 <hdoip_cli_fmt+0x158>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xdff(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1250 <hdoip_cli_fmt+0x110>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%edx
mov    $0x34000008,%esi
call   1030 <hoic_wr@plt>
jmp    1293 <hdoip_cli_fmt+0x153>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xdd1(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1282 <hdoip_cli_fmt+0x142>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%edx
mov    $0x34000009,%esi
call   1030 <hoic_wr@plt>
jmp    128e <hdoip_cli_fmt+0x14e>
lea    0xdab(%rip),%rdi
call   1050 <printf@plt>
jmp    1293 <hdoip_cli_fmt+0x153>
jmp    1298 <hdoip_cli_fmt+0x158>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdoip_cli_fmt>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %edi,%r14d
cmp    $0x3,%ecx
je     11ac <hdoip_cli_fmt+0x6c>
cmp    $0x2,%ecx
jne    11d4 <hdoip_cli_fmt+0x94>
mov    0x8(%rbx),%rdi
call   1050 <hdoip_lib_color_format@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%ebp
je     11cb <hdoip_cli_fmt+0x8b>
mov    (%rbx),%rdi
lea    0xe8f(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11e2 <hdoip_cli_fmt+0xa2>
mov    (%rbx),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11ec <hdoip_cli_fmt+0xac>
mov    (%rbx),%rdi
lea    0xe6e(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11f6 <hdoip_cli_fmt+0xb6>
lea    0xe75(%rip),%rdi
jmp    11db <hdoip_cli_fmt+0x9b>
mov    0x8(%rbx),%rdi
call   1050 <hdoip_lib_color_format@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   1050 <hdoip_lib_color_format@plt>
mov    %eax,%ebp
or     %r15d,%ebp
cmp    $0xffffffff,%ebp
jne    1167 <hdoip_cli_fmt+0x27>
lea    0xe5f(%rip),%rdi
jmp    11db <hdoip_cli_fmt+0x9b>
lea    0xe31(%rip),%rdi
call   1040 <puts@plt>
jmp    1205 <hdoip_cli_fmt+0xc5>
mov    %r14d,%edi
mov    $0x34000007,%esi
jmp    11fe <hdoip_cli_fmt+0xbe>
mov    %r14d,%edi
mov    $0x34000008,%esi
jmp    11fe <hdoip_cli_fmt+0xbe>
mov    %r14d,%edi
mov    $0x34000009,%esi
mov    %ebp,%edx
call   1030 <hoic_wr@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"too many arguments\0A\00"
@.str.1 = [20 x i8] c"unsupported format\0A\00"
@.str.2 = [3 x i8] c"in\00"
@.str.3 = [4 x i8] c"out\00"
@.str.4 = [5 x i8] c"proc\00"
@.str.5 = [19 x i8] c"unknown direction\0A\00"
define i32 @hdoip_cli_fmt(i32 %0, i32 %1, i8** %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8** %2, i8*** %8
store i32 %3, i32* %9
store i32 0, i32* %10
%11 = load i32, i32* %9
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = load i8**, i8*** %8
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @hdoip_lib_color_format(i8* %16)
store i32 %17, i32* %10
br label %35
18: ; preds = %4
%19 = load i32, i32* %9
%20 = icmp eq i32 %19, 3
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i8**, i8*** %8
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @hdoip_lib_color_format(i8* %24)
store i32 %25, i32* %10
%26 = load i8**, i8*** %8
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @hdoip_lib_color_format(i8* %28)
%30 = load i32, i32* %10
%31 = or i32 %30, %29
store i32 %31, i32* %10
br label %34
32: ; preds = %18
%33 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %5
br label %75
34: ; preds = %21
br label %35
35: ; preds = %34, %13
%36 = load i32, i32* %10
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %75
40: ; preds = %35
%41 = load i8**, i8*** %8
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %40
%47 = load i32, i32* %6
%48 = load i32, i32* %10
%49 = call i32 @hoic_wr(i32 %47, i32 872415239, i32 %48)
br label %74
50: ; preds = %40
%51 = load i8**, i8*** %8
%52 = getelementptr inbounds i8*, i8** %51, i64 0
%53 = load i8*, i8** %52
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %50
%57 = load i32, i32* %6
%58 = load i32, i32* %10
%59 = call i32 @hoic_wr(i32 %57, i32 872415240, i32 %58)
br label %73
60: ; preds = %50
%61 = load i8**, i8*** %8
%62 = getelementptr inbounds i8*, i8** %61, i64 0
%63 = load i8*, i8** %62
%64 = call i64 @strcmp(i8* %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%65 = icmp eq i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %60
%67 = load i32, i32* %6
%68 = load i32, i32* %10
%69 = call i32 @hoic_wr(i32 %67, i32 872415241, i32 %68)
br label %72
70: ; preds = %60
%71 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
br label %72
72: ; preds = %70, %66
br label %73
73: ; preds = %72, %56
br label %74
74: ; preds = %73, %46
store i32 0, i32* %5
br label %75
75: ; preds = %74, %38, %32
%76 = load i32, i32* %5
ret i32 %76
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"in\00"
@.str.3 = [4 x i8] c"out\00"
@.str.4 = [5 x i8] c"proc\00"
@str = [19 x i8] c"too many arguments\00"
@str.6 = [18 x i8] c"unknown direction\00"
@str.7 = [19 x i8] c"unsupported format\00"
define i32 @hdoip_cli_fmt(i32 %0, i32 %1, i8** nocapture %2, i32 %3) {
switch i32 %3, label %17 [
i32 2, label %5
i32 3, label %9
]
5: ; preds = %4
%6 = getelementptr inbounds i8*, i8** %2, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @hdoip_lib_color_format(i8* %7)
br label %19
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %2, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @hdoip_lib_color_format(i8* %11)
%13 = getelementptr inbounds i8*, i8** %2, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @hdoip_lib_color_format(i8* %14)
%16 = or i32 %15, %12
br label %19
17: ; preds = %4
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %44
19: ; preds = %9, %5
%20 = phi i32 [ %8, %5 ], [ %16, %9 ]
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
br label %44
24: ; preds = %19
%25 = load i8*, i8** %2
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @hoic_wr(i32 %0, i32 872415239, i32 %20)
br label %44
30: ; preds = %24
%31 = load i8*, i8** %2
%32 = tail call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = tail call i32 @hoic_wr(i32 %0, i32 872415240, i32 %20)
br label %44
36: ; preds = %30
%37 = load i8*, i8** %2
%38 = tail call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = tail call i32 @hoic_wr(i32 %0, i32 872415241, i32 %20)
br label %44
42: ; preds = %36
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.6, i64 0, i64 0))
br label %44
44: ; preds = %28, %40, %42, %34, %22, %17
ret i32 0
}