#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int *malloc(int);
int *maxSlidingWindow(int *, int, int, int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Usage: ./test k n1 n2...\n");
    exit(-1);
  }
  int i, size = argc - 2;
  int k = atoi(argv[1]);
  int *nums = malloc(size * sizeof(int));
  for (i = 0; i < size; i++) {
    nums[i] = atoi(argv[i + 2]);
  }
  int count = 0;
  int *lists = maxSlidingWindow(nums, size, k, &count);
  for (i = 0; i < count; i++) {
    printf("%d ", lists[i]);
  }
  printf("\n");
  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)
cmpl   $0x2,-0x8(%rbp)
jge    119f <main+0x3f>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    120f <main+0xaf>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d2 <main+0x72>
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
lea    -0x2c(%rbp),%rcx
call   1050 <maxSlidingWindow@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1267 <main+0x107>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1234 <main+0xd4>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@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
push   %rax
cmp    $0x1,%edi
jle    1245 <main+0xd5>
mov    %rsi,%r13
mov    %edi,%r12d
lea    -0x2(%r12),%r15d
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,0x4(%rsp)
lea    -0x8(,%r12,4),%edi
ff
call   1070 <malloc@plt>
mov    %rax,%r14
cmp    $0x2,%r12d
je     11d7 <main+0x67>
mov    %r15d,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    0x10(%r13,%rbp,8),%rdi
call   1080 <atoi@plt>
mov    %eax,(%r14,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    11c0 <main+0x50>
movl   $0x0,(%rsp)
mov    %rsp,%rcx
mov    %r14,%rdi
mov    %r15d,%esi
mov    0x4(%rsp),%edx
call   1060 <maxSlidingWindow@plt>
cmpl   $0x0,(%rsp)
jle    122a <main+0xba>
mov    %rax,%rbx
lea    0xe1a(%rip),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx,%rbp,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
movslq (%rsp),%rax
cmp    %rax,%rbp
jl     1210 <main+0xa0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: ./test k n1 n2...\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [2 x i8] c"\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*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i32, i32* %4
%20 = sub nsw i32 %19, 2
store i32 %20, i32* %7
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %8
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = trunc i64 %27 to i32
%29 = call i32* @malloc(i32 %28)
store i32* %29, i32** %9
store i32 0, i32* %6
br label %30
30: ; preds = %46, %18
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %49
34: ; preds = %30
%35 = load i8**, i8*** %5
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 2
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8*, i8** %35, i64 %38
%40 = load i8*, i8** %39
%41 = call i32 @atoi(i8* %40)
%42 = load i32*, i32** %9
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
store i32 %41, i32* %45
br label %46
46: ; preds = %34
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %30
49: ; preds = %30
store i32 0, i32* %10
%50 = load i32*, i32** %9
%51 = load i32, i32* %7
%52 = load i32, i32* %8
%53 = call i32* @maxSlidingWindow(i32* %50, i32 %51, i32 %52, i32* %10)
store i32* %53, i32** %11
store i32 0, i32* %6
br label %54
54: ; preds = %65, %49
%55 = load i32, i32* %6
%56 = load i32, i32* %10
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %68
58: ; preds = %54
%59 = load i32*, i32** %11
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i32, i32* %59, i64 %61
%63 = load i32, i32* %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %58
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
br label %54
68: ; preds = %54
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"Usage: ./test k n1 n2...\0A\00"
@.str.1 = [4 x i8] c"%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = add nsw i32 %0, -2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @atoi(i8* %12)
%14 = shl i32 %10, 2
%15 = tail call i32* @malloc(i32 %14)
%16 = icmp eq i32 %0, 2
br i1 %16, label %28, label %17
17: ; preds = %9
%18 = zext i32 %10 to i64
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %26, %19 ]
%21 = add nuw nsw i64 %20, 2
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = getelementptr inbounds i32, i32* %15, i64 %20
store i32 %24, i32* %25
%26 = add nuw nsw i64 %20, 1
%27 = icmp eq i64 %26, %18
br i1 %27, label %28, label %19
28: ; preds = %19, %9
%29 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%30 = call i32* @maxSlidingWindow(i32* %15, i32 %10, i32 %13, i32* %3)
%31 = load i32, i32* %3
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %42
33: ; preds = %28, %33
%34 = phi i64 [ %38, %33 ], [ 0, %28 ]
%35 = getelementptr inbounds i32, i32* %30, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = add nuw nsw i64 %34, 1
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = icmp slt i64 %38, %40
br i1 %41, label %33, label %42
42: ; preds = %33, %28
%43 = call i32 @putchar(i32 10)
ret i32 0
}