#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 atoi(char *);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(int *);
int get_min(int *, int, int, int);
int log2(int);
scalar_t__ malloc(int);
int *preprocess_min(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, int *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  int N = argc - 1;
  int *A = (int *)malloc(sizeof(int) * N);
  int *B;
  int a, b, logN = log2(N);
  printf("A = [");
  int i;
  for (i = 1; i < argc; i++) {
    A[i - 1] = atoi(argv[i]);
    printf("%d, ", A[i - 1]);
  }
  printf("]\n");
  B = preprocess_min(A, N);
  printf("B = [");
  for (i = 0; i < N * (logN + 1); i++) {
    if (i % N == 0 && i > 0)
      printf("\n     ");
    printf("%d, ", B[i]);
  }
  printf("]\n");
  while (!feof(stdin)) {
    int c = scanf("%d %d\n", &a, &b);
    if (c == 2) {
      int m = get_min(B, N, a, b);
      printf("Q(%d, %d) = %d\n", a, b, m);
    } else {
      fprintf(stderr, "Wrong query, it should b 2 integers per line\n");
    }
  }
  free(A);
  free(B);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <log2@plt>
mov    %eax,-0x34(%rbp)
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    124d <main+0xad>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edx
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11f2 <main+0x52>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1090 <preprocess_min@plt>
mov    %rax,-0x28(%rbp)
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    -0x34(%rbp),%edx
add    $0x1,%edx
imul   %edx,%ecx
cmp    %ecx,%eax
jge    12e6 <main+0x146>
mov    -0x38(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    12bf <main+0x11f>
cmpl   $0x0,-0x38(%rbp)
jle    12bf <main+0x11f>
lea    0xd5c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rax
movslq -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1280 <main+0xe0>
lea    0xd1e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1317 <main+0x177>
jmp    1383 <main+0x1e3>
lea    0xcfd(%rip),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   10b0 <scanf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x2,-0x3c(%rbp)
jne    1369 <main+0x1c9>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
call   1040 <get_min@plt>
mov    %eax,-0x40(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x40(%rbp),%ecx
lea    0xcc5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    137e <main+0x1de>
mov    0x2c68(%rip),%rax
mov    (%rax),%edi
lea    0xcb9(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12f4 <main+0x154>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    -0x1(%rbp),%r12d
lea    -0x4(,%rbp,4),%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    %r12d,%edi
call   1050 <log2@plt>
mov    %eax,0x14(%rsp)
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x2,%ebp
jl     1233 <main+0x83>
mov    %ebp,%ebp
add    $0xffffffffffffffff,%rbp
lea    0xe04(%rip),%r13
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rbx,%r15,8),%rdi
call   10d0 <atoi@plt>
mov    %eax,(%r14,%r15,4)
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1210 <main+0x60>
lea    0xe23(%rip),%rdi
call   1060 <puts@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   10a0 <preprocess_min@plt>
mov    %rax,%rbx
lea    0xdb7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x14(%rsp),%eax
add    $0x1,%eax
imul   %r12d,%eax
test   %eax,%eax
jle    12b5 <main+0x105>
mov    %eax,%r15d
lea    0xd92(%rip),%r13
xor    %ebp,%ebp
jmp    1296 <main+0xe6>
nopl   0x0(%rax,%rax,1)
mov    (%rbx,%rbp,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
je     12b5 <main+0x105>
mov    %ebp,%eax
cltd
idiv   %r12d
test   %rbp,%rbp
je     1280 <main+0xd0>
test   %edx,%edx
jne    1280 <main+0xd0>
lea    0xd65(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1280 <main+0xd0>
lea    0xda1(%rip),%rdi
call   1060 <puts@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1090 <feof@plt>
test   %eax,%eax
je     12f4 <main+0x144>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd1d(%rip),%r15
lea    0x10(%rsp),%rbp
lea    0xc(%rsp),%r13
jmp    1337 <main+0x187>
nopw   0x0(%rax,%rax,1)
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
lea    0xd0f(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   1090 <feof@plt>
test   %eax,%eax
jne    12d3 <main+0x123>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   10c0 <scanf@plt>
cmp    $0x2,%eax
jne    1310 <main+0x160>
mov    0x10(%rsp),%edx
mov    0xc(%rsp),%ecx
mov    %rbx,%rdi
mov    %r12d,%esi
call   1040 <get_min@plt>
mov    0x10(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xcb3(%rip),%rdi
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1325 <main+0x175>

LLVM IR (-O0):
@.str = [6 x i8] c"A = [\00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.2 = [3 x i8] c"]\0A\00"
@.str.3 = [6 x i8] c"B = [\00"
@.str.4 = [7 x i8] c"\0A \00"
@stdin = global i32 0
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [16 x i8] c"Q(%d, %d) = %d\0A\00"
@stderr = global i32 0
@.str.7 = [46 x i8] c"Wrong query, it should b 2 integers per line\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = sub nsw i32 %15, 1
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = mul i64 4, %18
%20 = trunc i64 %19 to i32
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %7
%23 = load i32, i32* %6
%24 = call i32 @log2(i32 %23)
store i32 %24, i32* %11
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %12
br label %26
26: ; preds = %49, %2
%27 = load i32, i32* %12
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %52
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i32, i32* %12
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
%37 = load i32*, i32** %7
%38 = load i32, i32* %12
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %37, i64 %40
store i32 %36, i32* %41
%42 = load i32*, i32** %7
%43 = load i32, i32* %12
%44 = sub nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %42, i64 %45
%47 = load i32, i32* %46
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %30
%50 = load i32, i32* %12
%51 = add nsw i32 %50, 1
store i32 %51, i32* %12
br label %26
52: ; preds = %26
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%54 = load i32*, i32** %7
%55 = load i32, i32* %6
%56 = call i32* @preprocess_min(i32* %54, i32 %55)
store i32* %56, i32** %8
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %12
br label %58
58: ; preds = %82, %52
%59 = load i32, i32* %12
%60 = load i32, i32* %6
%61 = load i32, i32* %11
%62 = add nsw i32 %61, 1
%63 = mul nsw i32 %60, %62
%64 = icmp slt i32 %59, %63
br i1 %64, label %65, label %85
65: ; preds = %58
%66 = load i32, i32* %12
%67 = load i32, i32* %6
%68 = srem i32 %66, %67
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %65
%71 = load i32, i32* %12
%72 = icmp sgt i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %70
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %75
75: ; preds = %73, %70, %65
%76 = load i32*, i32** %8
%77 = load i32, i32* %12
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i32, i32* %76, i64 %78
%80 = load i32, i32* %79
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %80)
br label %82
82: ; preds = %75
%83 = load i32, i32* %12
%84 = add nsw i32 %83, 1
store i32 %84, i32* %12
br label %58
85: ; preds = %58
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %87
87: ; preds = %109, %85
%88 = load i32, i32* @stdin
%89 = call i32 @feof(i32 %88)
%90 = icmp ne i32 %89, 0
%91 = xor i1 %90, true
br i1 %91, label %92, label %110
92: ; preds = %87
%93 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %9, i32* %10)
store i32 %93, i32* %13
%94 = load i32, i32* %13
%95 = icmp eq i32 %94, 2
br i1 %95, label %96, label %106
96: ; preds = %92
%97 = load i32*, i32** %8
%98 = load i32, i32* %6
%99 = load i32, i32* %9
%100 = load i32, i32* %10
%101 = call i32 @get_min(i32* %97, i32 %98, i32 %99, i32 %100)
store i32 %101, i32* %14
%102 = load i32, i32* %9
%103 = load i32, i32* %10
%104 = load i32, i32* %14
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %102, i32 %103, i32 %104)
br label %109
106: ; preds = %92
%107 = load i32, i32* @stderr
%108 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0))
br label %109
109: ; preds = %106, %96
br label %87
110: ; preds = %87
%111 = load i32*, i32** %7
%112 = call i32 @free(i32* %111)
%113 = load i32*, i32** %8
%114 = call i32 @free(i32* %113)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"A = [\00"
@.str.1 = [5 x i8] c"%d, \00"
@.str.3 = [6 x i8] c"B = [\00"
@.str.4 = [7 x i8] c"\0A \00"
@stdin = global i32 0
@.str.5 = [7 x i8] c"%d %d\0A\00"
@.str.6 = [16 x i8] c"Q(%d, %d) = %d\0A\00"
@stderr = global i32 0
@.str.7 = [46 x i8] c"Wrong query, it should b 2 integers per line\0A\00"
@str.8 = [2 x i8] c"]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = add nsw i32 %0, -1
%6 = shl i32 %5, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = tail call i32 @log2(i32 %5)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%13 = icmp sgt i32 %0, 1
br i1 %13, label %14, label %26
14: ; preds = %2
%15 = zext i32 %0 to i64
br label %16
16: ; preds = %14, %16
%17 = phi i64 [ 1, %14 ], [ %24, %16 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %17
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = add nsw i64 %17, -1
%22 = getelementptr inbounds i32, i32* %8, i64 %21
store i32 %20, i32* %22
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%24 = add nuw nsw i64 %17, 1
%25 = icmp eq i64 %24, %15
br i1 %25, label %26, label %16
26: ; preds = %16, %2
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.8, i64 0, i64 0))
%28 = tail call i32* @preprocess_min(i32* %8, i32 %5)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%30 = add nsw i32 %11, 1
%31 = mul i32 %30, %5
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %50
33: ; preds = %26
%34 = zext i32 %31 to i64
br label %35
35: ; preds = %33, %44
%36 = phi i64 [ 0, %33 ], [ %48, %44 ]
%37 = trunc i64 %36 to i32
%38 = srem i32 %37, %5
%39 = icmp eq i32 %38, 0
%40 = icmp ne i64 %36, 0
%41 = and i1 %40, %39
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %35
%45 = getelementptr inbounds i32, i32* %28, i64 %36
%46 = load i32, i32* %45
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = add nuw nsw i64 %36, 1
%49 = icmp eq i64 %48, %34
br i1 %49, label %50, label %35
50: ; preds = %44, %26
%51 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.8, i64 0, i64 0))
%52 = load i32, i32* @stdin
%53 = call i32 @feof(i32 %52)
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %72
55: ; preds = %50, %68
%56 = call i32 @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32* %3, i32* %4)
%57 = icmp eq i32 %56, 2
br i1 %57, label %58, label %65
58: ; preds = %55
%59 = load i32, i32* %3
%60 = load i32, i32* %4
%61 = call i32 @get_min(i32* %28, i32 %5, i32 %59, i32 %60)
%62 = load i32, i32* %3
%63 = load i32, i32* %4
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 %62, i32 %63, i32 %61)
br label %68
65: ; preds = %55
%66 = load i32, i32* @stderr
%67 = call i32 @fprintf(i32 %66, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.7, i64 0, i64 0))
br label %68
68: ; preds = %65, %58
%69 = load i32, i32* @stdin
%70 = call i32 @feof(i32 %69)
%71 = icmp eq i32 %70, 0
br i1 %71, label %55, label %72
72: ; preds = %68, %50
%73 = call i32 @free(i32* %8)
%74 = call i32 @free(i32* %28)
ret i32 0
}