#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 find(int *, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int scanf(char *, int *);
int main() {
  int n, case_number = 1;
  while (scanf("%d", &n) == 1) {
    printf("Case %d:\n", case_number++);
    int arr[n];
    for (int i = 0; i < n; i++)
      scanf("%d", arr + i);
    int q;
    scanf("%d", &q);
    while (q--) {
      int value;
      scanf("%d", &value);
      printf("Closest sum to %d is %d.\n", value, find(arr, n, value));
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1248 <main+0x118>
mov    -0xc(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
lea    0xe92(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11db <main+0xab>
mov    -0x38(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe38(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <main+0x76>
lea    0xe1e(%rip),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x28(%rbp)
cmp    $0x0,%eax
je     123c <main+0x10c>
lea    0xdfa(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%esi
mov    -0x2c(%rbp),%edx
call   1040 <find@plt>
mov    -0x3c(%rbp),%esi
mov    %eax,%edx
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11eb <main+0xbb>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
jmp    1146 <main+0x16>
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
lea    -0x2c(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1244 <main+0x114>
mov    $0x1,%ebx
lea    0xe9a(%rip),%r14
lea    0xea0(%rip),%r12
jmp    118f <main+0x5f>
nop
mov    -0x34(%rbp),%ebx
add    $0x1,%ebx
mov    -0x40(%rbp),%rsp
mov    %r14,%rdi
lea    -0x2c(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    1244 <main+0x114>
lea    0xe6d(%rip),%rdi
mov    %ebx,-0x34(%rbp)
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rsp,%r15
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
cmpl   $0x0,-0x2c(%rbp)
jle    11ec <main+0xbc>
mov    %r15,%r13
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
add    $0x4,%r13
cmp    %rax,%rbx
jl     11d0 <main+0xa0>
mov    %r14,%rdi
lea    -0x30(%rbp),%rsi
call   1050 <scanf@plt>
subl   $0x1,-0x30(%rbp)
lea    -0x38(%rbp),%r13
jb     1170 <main+0x40>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
mov    -0x38(%rbp),%ebx
mov    -0x2c(%rbp),%esi
mov    %r15,%rdi
mov    %ebx,%edx
call   1040 <find@plt>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
subl   $0x1,-0x30(%rbp)
jae    1210 <main+0xe0>
jmp    1170 <main+0x40>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"Case %d:\0A\00"
@.str.2 = [26 x i8] c"Closest sum to %d is %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
br label %9
9: ; preds = %45, %0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %47
12: ; preds = %9
%13 = load i32, i32* %3
%14 = add nsw i32 %13, 1
store i32 %14, i32* %3
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%16 = load i32, i32* %2
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %4
%19 = alloca i32, i64 %17
store i64 %17, i64* %5
store i32 0, i32* %6
br label %20
20: ; preds = %29, %12
%21 = load i32, i32* %6
%22 = load i32, i32* %2
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %19, i64 %26
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %27)
br label %29
29: ; preds = %24
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %20
32: ; preds = %20
%33 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
br label %34
34: ; preds = %38, %32
%35 = load i32, i32* %7
%36 = add nsw i32 %35, -1
store i32 %36, i32* %7
%37 = icmp ne i32 %35, 0
br i1 %37, label %38, label %45
38: ; preds = %34
%39 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%40 = load i32, i32* %8
%41 = load i32, i32* %2
%42 = load i32, i32* %8
%43 = call i32 @find(i32* %19, i32 %41, i32 %42)
%44 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %40, i32 %43)
br label %34
45: ; preds = %34
%46 = load i8*, i8** %4
br label %9
47: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [10 x i8] c"Case %d:\0A\00"
@.str.2 = [26 x i8] c"Closest sum to %d is %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %45
7: ; preds = %0
%8 = bitcast i32* %2 to i8*
%9 = bitcast i32* %3 to i8*
br label %10
10: ; preds = %7, %42
%11 = phi i32 [ 1, %7 ], [ %12, %42 ]
%12 = add nuw nsw i32 %11, 1
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%14 = load i32, i32* %1
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
%17 = alloca i32, i64 %15
%18 = load i32, i32* %1
%19 = icmp sgt i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %25, %10
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%22 = load i32, i32* %2
%23 = add nsw i32 %22, -1
store i32 %23, i32* %2
%24 = icmp eq i32 %22, 0
br i1 %24, label %42, label %33
25: ; preds = %10, %25
%26 = phi i64 [ %29, %25 ], [ 0, %10 ]
%27 = getelementptr inbounds i32, i32* %17, i64 %26
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %27)
%29 = add nuw nsw i64 %26, 1
%30 = load i32, i32* %1
%31 = sext i32 %30 to i64
%32 = icmp slt i64 %29, %31
br i1 %32, label %25, label %20
33: ; preds = %20, %33
%34 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%35 = load i32, i32* %3
%36 = load i32, i32* %1
%37 = call i32 @find(i32* %17, i32 %36, i32 %35)
%38 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %35, i32 %37)
%39 = load i32, i32* %2
%40 = add nsw i32 %39, -1
store i32 %40, i32* %2
%41 = icmp eq i32 %39, 0
br i1 %41, label %42, label %33
42: ; preds = %33, %20
%43 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%44 = icmp eq i32 %43, 1
br i1 %44, label %10, label %45
45: ; preds = %42, %0
ret i32 0
}