#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 */
size_t max_k(size_t, unsigned int *, size_t, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
int scanf(char *, ...);
int main(void) {
  printf("Enter the size of the array and the value of k, followed by the "
         "array elements.\n"
         "Use only elements in the range [%d, %d)\n",
         0, 10000);
  printf("> ");
  size_t arr_sz;
  size_t k;
  while (scanf("%zu%zu", &arr_sz, &k) == 2) {
    unsigned array[arr_sz];
    unsigned result[k];
    size_t i;
    for (i = 0; i < arr_sz; i++) {
      scanf("%u", &array[i]);
    }
    size_t written = max_k(k, result, arr_sz, array);
    printf("Max %zu = [ ", k);
    if (written > 0) {
      printf("%u", result[0]);
    }
    for (i = 1; i < written; i++) {
      printf(", %u", result[i]);
    }
    printf(" ];\n> ");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
xor    %esi,%esi
mov    $0x2710,%edx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf3b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf10(%rip),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
cmp    $0x2,%eax
jne    12b2 <main+0x182>
mov    -0x10(%rbp),%rax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    120e <main+0xde>
mov    -0x50(%rbp),%rsi
mov    -0x38(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11d2 <main+0xa2>
mov    -0x50(%rbp),%rcx
mov    -0x48(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
call   1040 <max_k@plt>
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x40(%rbp)
jbe    1258 <main+0x128>
mov    -0x48(%rbp),%rax
mov    (%rax),%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x1,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x40(%rbp),%rax
jae    1298 <main+0x168>
mov    -0x48(%rbp),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1260 <main+0x130>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    1162 <main+0x32>
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeb8(%rip),%rdi
xor    %esi,%esi
mov    $0x2710,%edx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf39(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf0e(%rip),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
cmp    $0x2,%eax
jne    12ac <main+0x17c>
lea    0xf05(%rip),%r14
jmp    11c1 <main+0x91>
nopl   0x0(%rax)
lea    0xefb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x40(%rbp),%rsp
lea    0xed0(%rip),%rdi
lea    -0x38(%rbp),%rsi
lea    -0x30(%rbp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
cmp    $0x2,%eax
jne    12ac <main+0x17c>
mov    %rsp,%rcx
mov    -0x38(%rbp),%rax
mov    %rsp,%r13
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    -0x30(%rbp),%rdi
mov    %rsp,%r12
lea    0xf(,%rdi,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
cmpq   $0x0,-0x38(%rbp)
mov    %rcx,-0x40(%rbp)
je     1240 <main+0x110>
mov    %r13,%rbx
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%r15
mov    -0x38(%rbp),%rdx
add    $0x4,%rbx
cmp    %rdx,%r15
jb     1210 <main+0xe0>
mov    -0x30(%rbp),%rdi
jmp    1242 <main+0x112>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edx,%edx
mov    %r12,%rsi
mov    %r13,%rcx
call   1040 <max_k@plt>
mov    %rax,%r15
mov    -0x30(%rbp),%rsi
lea    0xe25(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
test   %r15,%r15
lea    0xe21(%rip),%r13
je     1190 <main+0x60>
mov    (%r12),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x1,%r15
je     1190 <main+0x60>
mov    $0x1,%ebx
nop
mov    (%r12,%rbx,4),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1290 <main+0x160>
jmp    1190 <main+0x60>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [121 x i8] c"Enter the size of the array and the value of k, followed by the array elements.\0AUse only elements in the range [%d, %d)\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [7 x i8] c"%zu%zu\00"
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [13 x i8] c"Max %zu = [ \00"
@.str.5 = [5 x i8] c", %u\00"
@.str.6 = [7 x i8] c" ];\0A> \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0), i32 0, i32 10000)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %56, %0
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64* %2, i64* %3)
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %59
14: ; preds = %11
%15 = load i64, i64* %2
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %4
%17 = alloca i32, i64 %15
store i64 %15, i64* %5
%18 = load i64, i64* %3
%19 = alloca i32, i64 %18
store i64 %18, i64* %6
store i64 0, i64* %7
br label %20
20: ; preds = %28, %14
%21 = load i64, i64* %7
%22 = load i64, i64* %2
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i64, i64* %7
%26 = getelementptr inbounds i32, i32* %17, i64 %25
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %26)
br label %28
28: ; preds = %24
%29 = load i64, i64* %7
%30 = add i64 %29, 1
store i64 %30, i64* %7
br label %20
31: ; preds = %20
%32 = load i64, i64* %3
%33 = load i64, i64* %2
%34 = call i64 @max_k(i64 %32, i32* %19, i64 %33, i32* %17)
store i64 %34, i64* %8
%35 = load i64, i64* %3
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 %35)
%37 = load i64, i64* %8
%38 = icmp ugt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %31
%40 = getelementptr inbounds i32, i32* %19, i64 0
%41 = load i32, i32* %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %39, %31
store i64 1, i64* %7
br label %44
44: ; preds = %53, %43
%45 = load i64, i64* %7
%46 = load i64, i64* %8
%47 = icmp ult i64 %45, %46
br i1 %47, label %48, label %56
48: ; preds = %44
%49 = load i64, i64* %7
%50 = getelementptr inbounds i32, i32* %19, i64 %49
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %51)
br label %53
53: ; preds = %48
%54 = load i64, i64* %7
%55 = add i64 %54, 1
store i64 %55, i64* %7
br label %44
56: ; preds = %44
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%58 = load i8*, i8** %4
br label %11
59: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@.str = [121 x i8] c"Enter the size of the array and the value of k, followed by the array elements.\0AUse only elements in the range [%d, %d)\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [7 x i8] c"%zu%zu\00"
@.str.3 = [3 x i8] c"%u\00"
@.str.4 = [13 x i8] c"Max %zu = [ \00"
@.str.5 = [5 x i8] c", %u\00"
@.str.6 = [7 x i8] c" ];\0A> \00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([121 x i8], [121 x i8]* @.str, i64 0, i64 0), i32 0, i32 10000)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast i64* %1 to i8*
%6 = bitcast i64* %2 to i8*
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64* %1, i64* %2)
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %48
9: ; preds = %0, %44
%10 = load i64, i64* %1
%11 = call i8* @llvm.stacksave()
%12 = alloca i32, i64 %10
%13 = load i64, i64* %2
%14 = alloca i32, i64 %13
%15 = load i64, i64* %1
%16 = icmp eq i64 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %9, %17
%18 = phi i64 [ %21, %17 ], [ 0, %9 ]
%19 = getelementptr inbounds i32, i32* %12, i64 %18
%20 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %19)
%21 = add nuw i64 %18, 1
%22 = load i64, i64* %1
%23 = icmp ult i64 %21, %22
br i1 %23, label %17, label %24
24: ; preds = %17
%25 = load i64, i64* %2
br label %26
26: ; preds = %24, %9
%27 = phi i64 [ %13, %9 ], [ %25, %24 ]
%28 = phi i64 [ 0, %9 ], [ %22, %24 ]
%29 = call i64 @max_k(i64 %27, i32* %14, i64 %28, i32* %12)
%30 = load i64, i64* %2
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i64 %30)
%32 = icmp eq i64 %29, 0
br i1 %32, label %44, label %33
33: ; preds = %26
%34 = load i32, i32* %14
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = icmp eq i64 %29, 1
br i1 %36, label %44, label %37
37: ; preds = %33, %37
%38 = phi i64 [ %42, %37 ], [ 1, %33 ]
%39 = getelementptr inbounds i32, i32* %14, i64 %38
%40 = load i32, i32* %39
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %40)
%42 = add nuw i64 %38, 1
%43 = icmp eq i64 %42, %29
br i1 %43, label %44, label %37
44: ; preds = %37, %26, %33
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%46 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i64* %1, i64* %2)
%47 = icmp eq i32 %46, 2
br i1 %47, label %9, label %48
48: ; preds = %44, %0
ret i32 0
}