#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__ pid_t;

/* Variables and functions */
char **create_argv_for_execution_using_shell(char *);
scalar_t__ execute_ripper_encoder_with_plugin(char **, char **, scalar_t__ *,
                                              scalar_t__ *, int *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
int read_and_process_plugin_output(int, double *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ usleep(double);
int main(int argc, char **argv) {
  char *pg_com, *pi_com;
  char **pg_argv, **pi_argv;
  pid_t pg_pid, pi_pid;
  int read_fd;
  double progress;
  char msg[1024];
  int rs;
  if (argc != 3) {
    fprintf(stderr, "Syntax: ripperX_plugin_tester"
                    " \"program command with args\" \"plugin command\"\n");
    exit(1);
  }
  pg_com = argv[1];
  pi_com = argv[2];
  fprintf(stdout,
          "***Executing \"%s\"\n"
          "with plugin \"%s\"\n",
          pg_com, pi_com);
  pg_argv = create_argv_for_execution_using_shell(pg_com);
  pi_argv = create_argv_for_execution_using_shell(pi_com);
  pg_pid = 0;
  pi_pid = 0;
  if (execute_ripper_encoder_with_plugin(pg_argv, pi_argv, &pg_pid, &pi_pid,
                                         &read_fd) < 0)
    exit(1);
  while (1) {
    usleep(0.475 * 1000000);
    printf("\n");
    if ((rs = read_and_process_plugin_output(read_fd, &progress, msg)) == -1) {
      fprintf(stderr, "*** PLUGIN_MSG_PARSE_ERR returned\n");
      continue;
    }
    switch (rs) {
    case 0:
      printf("Report type : progress, Progress : %f,\nMsg : %s\n", progress,
             msg);
      break;
    case 1:
      printf("Report type : warning,\nMsg : %s\n", msg);
      break;
    case 2:
      printf("Report type : error,\nMsg : %s\n", msg);
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b4 <main+0x44>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <create_argv_for_execution_using_shell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <create_argv_for_execution_using_shell@plt>
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
lea    -0x44(%rbp),%r8
call   1040 <execute_ripper_encoder_with_plugin@plt>
cmp    $0x0,%rax
jge    1242 <main+0xd2>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1247 <main+0xd7>
movsd  0xdb1(%rip),%xmm0
call   1090 <usleep@plt>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x44(%rbp),%edi
lea    -0x450(%rbp),%rdx
lea    -0x50(%rbp),%rsi
call   1060 <read_and_process_plugin_output@plt>
mov    %eax,-0x454(%rbp)
cmp    $0xffffffff,%eax
jne    12a0 <main+0x130>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1247 <main+0xd7>
mov    -0x454(%rbp),%eax
mov    %eax,-0x458(%rbp)
test   %eax,%eax
je     12e1 <main+0x171>
jmp    12b9 <main+0x149>
mov    -0x458(%rbp),%eax
sub    $0x1,%eax
je     1300 <main+0x190>
jmp    12cd <main+0x15d>
mov    -0x458(%rbp),%eax
sub    $0x2,%eax
je     131a <main+0x1aa>
jmp    132f <main+0x1bf>
movsd  -0x50(%rbp),%xmm0
lea    -0x450(%rbp),%rsi
lea    0xda7(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    132f <main+0x1bf>
lea    -0x450(%rbp),%rsi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    132f <main+0x1bf>
lea    -0x450(%rbp),%rsi
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1247 <main+0xd7>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
cmp    $0x3,%edi
jne    12aa <main+0x12a>
mov    0x8(%rsi),%rbx
mov    0x10(%rsi),%rbp
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <create_argv_for_execution_using_shell@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1080 <create_argv_for_execution_using_shell@plt>
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x18(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x4(%rsp),%r8
mov    %rbx,%rdi
mov    %rax,%rsi
call   1050 <execute_ripper_encoder_with_plugin@plt>
test   %rax,%rax
js     12c1 <main+0x141>
lea    0x8(%rsp),%r14
lea    0x20(%rsp),%rbx
lea    0xdf0(%rip),%r15
lea    0xe8c(%rip),%r12
lea    0xeb6(%rip),%r13
lea    0xed0(%rip),%rbp
jmp    123d <main+0xbd>
nop
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
movsd  0xdbb(%rip),%xmm0
call   10a0 <usleep@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <read_and_process_plugin_output@plt>
add    $0x1,%eax
cmp    $0x3,%eax
ja     123d <main+0xbd>
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    123d <main+0xbd>
nopl   (%rax)
mov    %rbp,%rdi
jmp    1233 <main+0xb3>
movsd  0x8(%rsp),%xmm0
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    123d <main+0xbd>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [76 x i8] c"Syntax: ripperX_plugin_tester \22program command with args\22 \22plugin command\22\0A\00"
@stdout = global i32 0
@.str.1 = [36 x i8] c"***Executing \22%s\22\0Awith plugin \22%s\22\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [35 x i8] c"*** PLUGIN_MSG_PARSE_ERR returned\0A\00"
@.str.4 = [49 x i8] c"Report type : progress, Progress : %f,\0AMsg : %s\0A\00"
@.str.5 = [33 x i8] c"Report type : warning,\0AMsg : %s\0A\00"
@.str.6 = [31 x i8] c"Report type : error,\0AMsg : %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i64
%11 = alloca i64
%12 = alloca i32
%13 = alloca double
%14 = alloca [1024 x i8]
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 3
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
store i8* %25, i8** %6
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
store i8* %28, i8** %7
%29 = load i32, i32* @stdout
%30 = load i8*, i8** %6
%31 = load i8*, i8** %7
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
%33 = load i8*, i8** %6
%34 = call i8** @create_argv_for_execution_using_shell(i8* %33)
store i8** %34, i8*** %8
%35 = load i8*, i8** %7
%36 = call i8** @create_argv_for_execution_using_shell(i8* %35)
store i8** %36, i8*** %9
store i64 0, i64* %10
store i64 0, i64* %11
%37 = load i8**, i8*** %8
%38 = load i8**, i8*** %9
%39 = call i64 @execute_ripper_encoder_with_plugin(i8** %37, i8** %38, i64* %10, i64* %11, i32* %12)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %22
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %22
br label %44
44: ; preds = %43, %51, %66
%45 = call i32 @usleep(double 4.750000e+05)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%47 = load i32, i32* %12
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%49 = call i32 @read_and_process_plugin_output(i32 %47, double* %13, i8* %48)
store i32 %49, i32* %15
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %44
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %44
54: ; preds = %44
%55 = load i32, i32* %15
switch i32 %55, label %66 [
i32 0, label %56
i32 1, label %60
i32 2, label %63
]
56: ; preds = %54
%57 = load double, double* %13
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), double %57, i8* %58)
br label %66
60: ; preds = %54
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %61)
br label %66
63: ; preds = %54
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %64)
br label %66
66: ; preds = %54, %63, %60, %56
br label %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [76 x i8] c"Syntax: ripperX_plugin_tester \22program command with args\22 \22plugin command\22\0A\00"
@stdout = global i32 0
@.str.1 = [36 x i8] c"***Executing \22%s\22\0Awith plugin \22%s\22\0A\00"
@.str.3 = [35 x i8] c"*** PLUGIN_MSG_PARSE_ERR returned\0A\00"
@.str.4 = [49 x i8] c"Report type : progress, Progress : %f,\0AMsg : %s\0A\00"
@.str.5 = [33 x i8] c"Report type : warning,\0AMsg : %s\0A\00"
@.str.6 = [31 x i8] c"Report type : error,\0AMsg : %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca double
%7 = alloca [1024 x i8]
%8 = bitcast i64* %3 to i8*
%9 = bitcast i64* %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = bitcast double* %6 to i8*
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = icmp eq i32 %0, 3
br i1 %13, label %18, label %14
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @stdout
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %22)
%25 = tail call i8** @create_argv_for_execution_using_shell(i8* %20)
%26 = tail call i8** @create_argv_for_execution_using_shell(i8* %22)
store i64 0, i64* %3
store i64 0, i64* %4
%27 = call i64 @execute_ripper_encoder_with_plugin(i8** %25, i8** %26, i64* %3, i64* %4, i32* %5)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %18
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %18, %42
%32 = call i32 @usleep(double 4.750000e+05)
%33 = call i32 @putchar(i32 10)
%34 = load i32, i32* %5
%35 = call i32 @read_and_process_plugin_output(i32 %34, double* %6, i8* %12)
switch i32 %35, label %42 [
i32 -1, label %36
i32 0, label %39
i32 1, label %43
i32 2, label %45
]
36: ; preds = %31
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0))
br label %42
39: ; preds = %31
%40 = load double, double* %6
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), double %40, i8* %12)
br label %42
42: ; preds = %39, %43, %45, %31, %36
br label %31
43: ; preds = %31
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %12)
br label %42
45: ; preds = %31
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* %12)
br label %42
}