#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 prime(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int i, j, num, flag;
  while (1) {
    scanf("%d", &num);
    if (num == 0)
      break;
    if (num % 2 == 0)
      num--;
    for (i = num;; i -= 2) {
      if (prime(i - 8) == 1 && prime(i - 6) == 1 && prime(i - 2) == 1 &&
          prime(i) == 1)
        break;
    }
    printf("%d\n", i);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x10(%rbp)
jne    115e <main+0x2e>
jmp    11fa <main+0xca>
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117b <main+0x4b>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
sub    $0x8,%edi
call   1050 <prime@plt>
cmp    $0x1,%eax
jne    11d3 <main+0xa3>
mov    -0x8(%rbp),%edi
sub    $0x6,%edi
call   1050 <prime@plt>
cmp    $0x1,%eax
jne    11d3 <main+0xa3>
mov    -0x8(%rbp),%edi
sub    $0x2,%edi
call   1050 <prime@plt>
cmp    $0x1,%eax
jne    11d3 <main+0xa3>
mov    -0x8(%rbp),%edi
call   1050 <prime@plt>
cmp    $0x1,%eax
jne    11d3 <main+0xa3>
jmp    11e6 <main+0xb6>
jmp    11d8 <main+0xa8>
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
jmp    1181 <main+0x51>
mov    -0x8(%rbp),%esi
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
jmp    113f <main+0xf>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%ebx
test   %ebx,%ebx
je     11d3 <main+0xa3>
lea    0xea7(%rip),%r14
lea    0xe9d(%rip),%r15
lea    0x4(%rsp),%r12
nopl   0x0(%rax,%rax,1)
test   $0x1,%bl
jne    1183 <main+0x53>
add    $0xffffffff,%ebx
mov    %ebx,0x4(%rsp)
jmp    1183 <main+0x53>
xchg   %ax,%ax
add    $0xfffffffe,%ebx
lea    -0x8(%rbx),%edi
call   1050 <prime@plt>
cmp    $0x1,%eax
jne    1180 <main+0x50>
lea    -0x6(%rbx),%edi
call   1050 <prime@plt>
cmp    $0x1,%eax
jne    1180 <main+0x50>
lea    -0x2(%rbx),%edi
call   1050 <prime@plt>
cmp    $0x1,%eax
jne    1180 <main+0x50>
mov    %ebx,%edi
call   1050 <prime@plt>
cmp    $0x1,%eax
jne    1180 <main+0x50>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%ebx
test   %ebx,%ebx
jne    1170 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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