#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*/ regex_t;

/* Variables and functions */
int begin(int /*<<< orphan*/ *);
int grep(char **);
int pass(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
scalar_t__ strcmp(char const *, char *);
int usage(char *);
int main(int argc, char *argv[]) {
  const char *type;
  regex_t regex;
  if (argc < 3) {
    printf("Error: invalid number of arguments: %d\n", argc);
    return usage(argv[0]);
  }
  type = argv[1];
  if (!strcmp(type, "grep"))
    return grep(&argv[2]);
  if (regcomp(&regex, argv[2], 0)) {
    perror("regcomp");
    return usage(argv[0]);
  }
  if (!strcmp(type, "begin"))
    return begin(&regex);
  if (strcmp(type, "include") && strcmp(type, "exclude")) {
    printf("Error: invalid filter type '%s'\n", type);
    return usage(argv[0]);
  }
  return pass(&regex, !strcmp(type, "exclude"));
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11c5 <main+0x45>
mov    -0x8(%rbp),%esi
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12ec <main+0x16c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1200 <main+0x80>
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
call   1050 <grep@plt>
mov    %eax,-0x4(%rbp)
jmp    12ec <main+0x16c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x1c(%rbp),%rdi
xor    %edx,%edx
call   1060 <regcomp@plt>
cmp    $0x0,%rax
je     123d <main+0xbd>
lea    0xe09(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12ec <main+0x16c>
mov    -0x18(%rbp),%rdi
lea    0xded(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1268 <main+0xe8>
lea    -0x1c(%rbp),%rdi
call   1090 <begin@plt>
mov    %eax,-0x4(%rbp)
jmp    12ec <main+0x16c>
mov    -0x18(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12c2 <main+0x142>
mov    -0x18(%rbp),%rdi
lea    0xdb6(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12c2 <main+0x142>
mov    -0x18(%rbp),%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <usage@plt>
mov    %eax,-0x4(%rbp)
jmp    12ec <main+0x16c>
mov    -0x18(%rbp),%rdi
lea    0xd76(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
lea    -0x1c(%rbp),%rdi
call   1030 <pass@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     11ab <main+0x2b>
mov    %edi,%esi
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1080 <usage@plt>
mov    0x8(%rbx),%r14
lea    0xe72(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
lea    0x10(%rbx),%rdi
test   %rax,%rax
je     122e <main+0xae>
mov    (%rdi),%rsi
lea    0x4(%rsp),%rdi
xor    %edx,%edx
call   1060 <regcomp@plt>
test   %rax,%rax
jne    126a <main+0xea>
lea    0xe4f(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     123a <main+0xba>
lea    0xe41(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1246 <main+0xc6>
lea    0xe35(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1246 <main+0xc6>
lea    0xe29(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1276 <main+0xf6>
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <grep@plt>
lea    0x4(%rsp),%rdi
call   1090 <begin@plt>
jmp    127e <main+0xfe>
lea    0xdf6(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcmp@plt>
xor    %esi,%esi
test   %rax,%rax
sete   %sil
lea    0x4(%rsp),%rdi
call   1030 <pass@plt>
jmp    127e <main+0xfe>
lea    0xdbc(%rip),%rdi
call   10a0 <perror@plt>
mov    (%rbx),%rdi
call   1080 <usage@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Error: invalid number of arguments: %d\0A\00"
@.str.1 = [5 x i8] c"grep\00"
@.str.2 = [8 x i8] c"regcomp\00"
@.str.3 = [6 x i8] c"begin\00"
@.str.4 = [8 x i8] c"include\00"
@.str.5 = [8 x i8] c"exclude\00"
@.str.6 = [33 x i8] c"Error: invalid filter type '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i8* %15)
store i32 %16, i32* %3
br label %68
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = call i32 @grep(i8** %26)
store i32 %27, i32* %3
br label %68
28: ; preds = %17
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i64 @regcomp(i32* %7, i8* %31, i32 0)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %28
%35 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = call i32 @usage(i8* %38)
store i32 %39, i32* %3
br label %68
40: ; preds = %28
%41 = load i8*, i8** %6
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = call i32 @begin(i32* %7)
store i32 %45, i32* %3
br label %68
46: ; preds = %40
%47 = load i8*, i8** %6
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%49 = icmp ne i64 %48, 0
br i1 %49, label %50, label %61
50: ; preds = %46
%51 = load i8*, i8** %6
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %61
54: ; preds = %50
%55 = load i8*, i8** %6
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %55)
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 0
%59 = load i8*, i8** %58
%60 = call i32 @usage(i8* %59)
store i32 %60, i32* %3
br label %68
61: ; preds = %50, %46
%62 = load i8*, i8** %6
%63 = call i64 @strcmp(i8* %62, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%64 = icmp ne i64 %63, 0
%65 = xor i1 %64, true
%66 = zext i1 %65 to i32
%67 = call i32 @pass(i32* %7, i32 %66)
store i32 %67, i32* %3
br label %68
68: ; preds = %61, %54, %44, %34, %24, %10
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [40 x i8] c"Error: invalid number of arguments: %d\0A\00"
@.str.1 = [5 x i8] c"grep\00"
@.str.2 = [8 x i8] c"regcomp\00"
@.str.3 = [6 x i8] c"begin\00"
@.str.4 = [8 x i8] c"include\00"
@.str.5 = [8 x i8] c"exclude\00"
@.str.6 = [33 x i8] c"Error: invalid filter type '%s'\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = load i8*, i8** %1
%9 = tail call i32 @usage(i8* %8)
br label %46
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
%15 = getelementptr inbounds i8*, i8** %1, i64 2
br i1 %14, label %16, label %18
16: ; preds = %10
%17 = tail call i32 @grep(i8** %15)
br label %46
18: ; preds = %10
%19 = load i8*, i8** %15
%20 = call i64 @regcomp(i32* %3, i8* %19, i32 0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%24 = load i8*, i8** %1
%25 = call i32 @usage(i8* %24)
br label %46
26: ; preds = %18
%27 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @begin(i32* %3)
br label %46
31: ; preds = %26
%32 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %41, label %34
34: ; preds = %31
%35 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%39 = load i8*, i8** %1
%40 = call i32 @usage(i8* %39)
br label %46
41: ; preds = %34, %31
%42 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @pass(i32* %3, i32 %44)
br label %46
46: ; preds = %41, %37, %29, %22, %16, %6
%47 = phi i32 [ %9, %6 ], [ %25, %22 ], [ %40, %37 ], [ %45, %41 ], [ %30, %29 ], [ %17, %16 ]
ret i32 %47
}