#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 scalar_t__ uint32_t;

/* Variables and functions */
int EINVAL;
int del_filter(scalar_t__);
int get_filter_mode();
int set_filter(scalar_t__, int, char const **);
int set_filter_mode(int, char const **);
int show_filters();
char *str_to_number(char const *, int /*<<< orphan*/ *, long long *);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ warnx(char *, ...);
int filter_cmd(int argc, const char *argv[]) {
  long long val;
  uint32_t idx;
  char *s;
  if (argc == 0) {
    warnx("filter: no arguments.");
    return (EINVAL);
  };
  if (strcmp(argv[0], "list") == 0) {
    if (argc != 1)
      warnx("trailing arguments after \"list\" ignored.");
    return show_filters();
  }
  if (argc == 1 && strcmp(argv[0], "mode") == 0)
    return get_filter_mode();
  if (strcmp(argv[0], "mode") == 0)
    return set_filter_mode(argc - 1, argv + 1);
  s = str_to_number(argv[0], NULL, &val);
  if (*s || val > 0xffffffffU) {
    warnx("\"%s\" is neither an index nor a filter subcommand.", argv[0]);
    return (EINVAL);
  }
  idx = (uint32_t)val;
  if (argc == 2 &&
      (strcmp(argv[1], "delete") == 0 || strcmp(argv[1], "clear") == 0)) {
    return del_filter(idx);
  }
  return set_filter(idx, argc - 1, argv + 1);
}


x86 assembly (clang, -O0):
<filter_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11b8 <filter_cmd+0x38>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1340 <filter_cmd+0x1c0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe50(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    11fc <filter_cmd+0x7c>
cmpl   $0x1,-0x8(%rbp)
je     11ed <filter_cmd+0x6d>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
mov    $0x0,%al
call   1080 <show_filters@plt>
mov    %eax,-0x4(%rbp)
jmp    1340 <filter_cmd+0x1c0>
cmpl   $0x1,-0x8(%rbp)
jne    1232 <filter_cmd+0xb2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe30(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1232 <filter_cmd+0xb2>
mov    $0x0,%al
call   1060 <get_filter_mode@plt>
mov    %eax,-0x4(%rbp)
jmp    1340 <filter_cmd+0x1c0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe04(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    126a <filter_cmd+0xea>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1030 <set_filter_mode@plt>
mov    %eax,-0x4(%rbp)
jmp    1340 <filter_cmd+0x1c0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
lea    -0x18(%rbp),%rdx
call   1050 <str_to_number@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12a1 <filter_cmd+0x121>
mov    $0xffffffff,%eax
cmp    %rax,-0x18(%rbp)
jle    12c7 <filter_cmd+0x147>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd9a(%rip),%rdi
mov    $0x0,%al
call   1070 <warnx@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1340 <filter_cmd+0x1c0>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1326 <filter_cmd+0x1a6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd93(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1315 <filter_cmd+0x195>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd7c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1326 <filter_cmd+0x1a6>
mov    -0x20(%rbp),%rdi
call   1040 <del_filter@plt>
mov    %eax,-0x4(%rbp)
jmp    1340 <filter_cmd+0x1c0>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%esi
sub    $0x1,%esi
mov    -0x10(%rbp),%rdx
add    $0x8,%rdx
call   10a0 <set_filter@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_cmd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %edi,%edi
je     125f <filter_cmd+0xdf>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    (%rsi),%rdi
lea    0xe77(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     126f <filter_cmd+0xef>
cmp    $0x1,%ebp
jne    11ca <filter_cmd+0x4a>
mov    (%rbx),%rdi
lea    0xe88(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12cd <filter_cmd+0x14d>
mov    (%rbx),%rdi
lea    0xe70(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1291 <filter_cmd+0x111>
mov    (%rbx),%rdi
lea    0x8(%rsp),%rdx
xor    %esi,%esi
call   1050 <str_to_number@plt>
cmpb   $0x0,(%rax)
jne    12aa <filter_cmd+0x12a>
mov    0x8(%rsp),%r14
movabs $0x100000000,%rax
cmp    %rax,%r14
jge    12aa <filter_cmd+0x12a>
cmp    $0x2,%ebp
jne    1249 <filter_cmd+0xc9>
mov    0x8(%rbx),%rdi
lea    0xe59(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12dc <filter_cmd+0x15c>
mov    0x8(%rbx),%rdi
lea    0xe47(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12dc <filter_cmd+0x15c>
add    $0xffffffff,%ebp
add    $0x8,%rbx
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
call   10a0 <set_filter@plt>
jmp    12c4 <filter_cmd+0x144>
lea    0xd9a(%rip),%rdi
xor    %eax,%eax
call   1070 <warnx@plt>
jmp    12bb <filter_cmd+0x13b>
cmp    $0x1,%ebp
je     1282 <filter_cmd+0x102>
lea    0xda0(%rip),%rdi
xor    %eax,%eax
call   1070 <warnx@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <show_filters@plt>
add    $0xffffffff,%ebp
add    $0x8,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <set_filter_mode@plt>
mov    (%rbx),%rsi
lea    0xd95(%rip),%rdi
xor    %eax,%eax
call   1070 <warnx@plt>
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <get_filter_mode@plt>
mov    %r14,%rdi
call   1040 <del_filter@plt>
jmp    12c4 <filter_cmd+0x144>

LLVM IR (-O0):
@.str = [22 x i8] c"filter: no arguments.\00"
@EINVAL = global i32 0
@.str.1 = [5 x i8] c"list\00"
@.str.2 = [41 x i8] c"trailing arguments after \22list\22 ignored.\00"
@.str.3 = [5 x i8] c"mode\00"
@.str.4 = [50 x i8] c"\22%s\22 is neither an index nor a filter subcommand.\00"
@.str.5 = [7 x i8] c"delete\00"
@.str.6 = [6 x i8] c"clear\00"
define i32 @filter_cmd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EINVAL
store i32 %13, i32* %3
br label %94
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %14
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %20
%26 = call i32 (...) @show_filters()
store i32 %26, i32* %3
br label %94
27: ; preds = %14
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 (...) @get_filter_mode()
store i32 %37, i32* %3
br label %94
38: ; preds = %30, %27
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %38
%45 = load i32, i32* %4
%46 = sub nsw i32 %45, 1
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = call i32 @set_filter_mode(i32 %46, i8** %48)
store i32 %49, i32* %3
br label %94
50: ; preds = %38
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 0
%53 = load i8*, i8** %52
%54 = call i8* @str_to_number(i8* %53, i32* null, i64* %6)
store i8* %54, i8** %8
%55 = load i8*, i8** %8
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 0
br i1 %58, label %62, label %59
59: ; preds = %50
%60 = load i64, i64* %6
%61 = icmp sgt i64 %60, 4294967295
br i1 %61, label %62, label %68
62: ; preds = %59, %50
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 0
%65 = load i8*, i8** %64
%66 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* %65)
%67 = load i32, i32* @EINVAL
store i32 %67, i32* %3
br label %94
68: ; preds = %59
%69 = load i64, i64* %6
store i64 %69, i64* %7
%70 = load i32, i32* %4
%71 = icmp eq i32 %70, 2
br i1 %71, label %72, label %87
72: ; preds = %68
%73 = load i8**, i8*** %5
%74 = getelementptr inbounds i8*, i8** %73, i64 1
%75 = load i8*, i8** %74
%76 = call i64 @strcmp(i8* %75, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%77 = icmp eq i64 %76, 0
br i1 %77, label %84, label %78
78: ; preds = %72
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i64 @strcmp(i8* %81, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %78, %72
%85 = load i64, i64* %7
%86 = call i32 @del_filter(i64 %85)
store i32 %86, i32* %3
br label %94
87: ; preds = %78, %68
%88 = load i64, i64* %7
%89 = load i32, i32* %4
%90 = sub nsw i32 %89, 1
%91 = load i8**, i8*** %5
%92 = getelementptr inbounds i8*, i8** %91, i64 1
%93 = call i32 @set_filter(i64 %88, i32 %90, i8** %92)
store i32 %93, i32* %3
br label %94
94: ; preds = %87, %84, %62, %44, %36, %25, %11
%95 = load i32, i32* %3
ret i32 %95
}

LLVM IR (-O2):
@.str = [22 x i8] c"filter: no arguments.\00"
@EINVAL = global i32 0
@.str.1 = [5 x i8] c"list\00"
@.str.2 = [41 x i8] c"trailing arguments after \22list\22 ignored.\00"
@.str.3 = [5 x i8] c"mode\00"
@.str.4 = [50 x i8] c"\22%s\22 is neither an index nor a filter subcommand.\00"
@.str.5 = [7 x i8] c"delete\00"
@.str.6 = [6 x i8] c"clear\00"
define i32 @filter_cmd(i32 %0, i8** %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = icmp eq i32 %0, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EINVAL
br label %63
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = icmp eq i32 %0, 1
br i1 %12, label %14, label %19
14: ; preds = %9
br i1 %13, label %17, label %15
15: ; preds = %14
%16 = tail call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %15, %14
%18 = tail call i32 (...) @show_filters()
br label %63
19: ; preds = %9
br i1 %13, label %20, label %26
20: ; preds = %19
%21 = load i8*, i8** %1
%22 = tail call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 (...) @get_filter_mode()
br label %63
26: ; preds = %20, %19
%27 = load i8*, i8** %1
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %26
%31 = add nsw i32 %0, -1
%32 = getelementptr inbounds i8*, i8** %1, i64 1
%33 = tail call i32 @set_filter_mode(i32 %31, i8** %32)
br label %63
34: ; preds = %26
%35 = load i8*, i8** %1
%36 = call i8* @str_to_number(i8* %35, i32* null, i64* %3)
%37 = load i8, i8* %36
%38 = icmp ne i8 %37, 0
%39 = load i64, i64* %3
%40 = icmp sgt i64 %39, 4294967295
%41 = select i1 %38, i1 true, i1 %40
br i1 %41, label %42, label %46
42: ; preds = %34
%43 = load i8*, i8** %1
%44 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @EINVAL
br label %63
46: ; preds = %34
%47 = icmp eq i32 %0, 2
br i1 %47, label %48, label %59
48: ; preds = %46
%49 = getelementptr inbounds i8*, i8** %1, i64 1
%50 = load i8*, i8** %49
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %48
%54 = load i8*, i8** %49
%55 = call i64 @strcmp(i8* %54, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53, %48
%58 = call i32 @del_filter(i64 %39)
br label %63
59: ; preds = %53, %46
%60 = add nsw i32 %0, -1
%61 = getelementptr inbounds i8*, i8** %1, i64 1
%62 = call i32 @set_filter(i64 %39, i32 %60, i8** %61)
br label %63
63: ; preds = %59, %57, %42, %30, %24, %17, %6
%64 = phi i32 [ %8, %6 ], [ %18, %17 ], [ %25, %24 ], [ %33, %30 ], [ %45, %42 ], [ %58, %57 ], [ %62, %59 ]
ret i32 %64
}