#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*/ WSQ_Init(char *);
int /*<<< orphan*/ WSQ_Pause();
int /*<<< orphan*/ WSQ_SetQueryName(char *);
int /*<<< orphan*/ abort();
int atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ query_A();
int /*<<< orphan*/ query_B();
int /*<<< orphan*/ query_C();
int /*<<< orphan*/ sprintf(char *, char *, int);
int main(int argc, char *argv[]) {
  if (argc < 2) {
    printf("ERROR: Usage: 3_TAQ_merge_over_socket [1,2,3]");
    printf("Runs component 1, 2, or 3 of the three-part query.");
    abort();
  }
  int mode = atoi(argv[1]);
  printf("Building query fragment, mode %d\n", mode);
  char name[256];
  WSQ_Init("");
  sprintf(name, "generated_query_3%d", mode);
  WSQ_SetQueryName(name);
  WSQ_Pause();
  printf("PAUSED WSQ engine, run compiled query manually...\n");
  switch (mode) {
  case 1:
    query_A();
    break;
  case 2:
    query_B();
    break;
  case 3:
    query_C();
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11e6 <main+0x46>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe61(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x125(%rbp)
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
call   1060 <WSQ_Init@plt>
mov    -0x14(%rbp),%edx
lea    0xe60(%rip),%rsi
lea    -0x120(%rbp),%rdi
mov    %rdi,-0x130(%rbp)
call   10b0 <sprintf@plt>
mov    -0x130(%rbp),%rdi
call   1070 <WSQ_SetQueryName@plt>
mov    -0x125(%rbp),%al
call   10c0 <WSQ_Pause@plt>
mov    -0x125(%rbp),%al
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x124(%rbp)
sub    $0x1,%eax
je     129e <main+0xfe>
jmp    1276 <main+0xd6>
mov    -0x124(%rbp),%eax
sub    $0x2,%eax
je     12aa <main+0x10a>
jmp    128a <main+0xea>
mov    -0x124(%rbp),%eax
sub    $0x3,%eax
je     12b6 <main+0x116>
jmp    12bd <main+0x11d>
mov    $0x0,%al
call   1090 <query_A@plt>
jmp    12bd <main+0x11d>
mov    $0x0,%al
call   1050 <query_B@plt>
jmp    12bd <main+0x11d>
mov    $0x0,%al
call   1080 <query_C@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x108,%rsp
cmp    $0x1,%edi
jle    124e <main+0x9e>
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%ebx
lea    0xe8c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9d(%rip),%rdi
call   1070 <WSQ_Init@plt>
lea    0xe92(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   10c0 <sprintf@plt>
mov    %r14,%rdi
call   1080 <WSQ_SetQueryName@plt>
xor    %eax,%eax
call   10d0 <WSQ_Pause@plt>
lea    0xe83(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x3,%ebx
je     123a <main+0x8a>
cmp    $0x2,%ebx
je     1231 <main+0x81>
cmp    $0x1,%ebx
jne    1241 <main+0x91>
xor    %eax,%eax
call   10a0 <query_A@plt>
jmp    1241 <main+0x91>
xor    %eax,%eax
call   1060 <query_B@plt>
jmp    1241 <main+0x91>
xor    %eax,%eax
call   1090 <query_C@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdab(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xdcb(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"ERROR: Usage: 3_TAQ_merge_over_socket [1,2,3]\00"
@.str.1 = [51 x i8] c"Runs component 1, 2, or 3 of the three-part query.\00"
@.str.2 = [34 x i8] c"Building query fragment, mode %d\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [20 x i8] c"generated_query_3%d\00"
@.str.5 = [51 x i8] c"PAUSED WSQ engine, run compiled query manually...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
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, 2
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 @WSQ_Init(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%23 = load i32, i32* %6
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%26 = call i32 @WSQ_SetQueryName(i8* %25)
%27 = call i32 (...) @WSQ_Pause()
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0))
%29 = load i32, i32* %6
switch i32 %29, label %36 [
i32 1, label %30
i32 2, label %32
i32 3, label %34
]
30: ; preds = %14
%31 = call i32 (...) @query_A()
br label %36
32: ; preds = %14
%33 = call i32 (...) @query_B()
br label %36
34: ; preds = %14
%35 = call i32 (...) @query_C()
br label %36
36: ; preds = %14, %34, %32, %30
ret i32 0
}

LLVM IR (-O2):
@.str = [46 x i8] c"ERROR: Usage: 3_TAQ_merge_over_socket [1,2,3]\00"
@.str.1 = [51 x i8] c"Runs component 1, 2, or 3 of the three-part query.\00"
@.str.2 = [34 x i8] c"Building query fragment, mode %d\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [20 x i8] c"generated_query_3%d\00"
@str = [50 x i8] c"PAUSED WSQ engine, run compiled query manually...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%15 = tail call i32 @WSQ_Init(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @sprintf(i8* %14, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%17 = call i32 @WSQ_SetQueryName(i8* %14)
%18 = call i32 (...) @WSQ_Pause()
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str, i64 0, i64 0))
switch i32 %12, label %26 [
i32 1, label %20
i32 2, label %22
i32 3, label %24
]
20: ; preds = %9
%21 = call i32 (...) @query_A()
br label %26
22: ; preds = %9
%23 = call i32 (...) @query_B()
br label %26
24: ; preds = %9
%25 = call i32 (...) @query_C()
br label %26
26: ; preds = %9, %24, %22, %20
ret i32 0
}