#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 /*<<< orphan*/ printf(char *, ...);
scalar_t__ scanf(char *, int *);
int main() {
  int c, p = -1, pp = -1, t, r2[4] = {2, 4, 8, 6}, r3[4] = {3, 9, 7, 1},
         r4[2] = {4, 6};
  while (scanf("%1d", &c) > 0) {
    pp = p;
    p = c;
  }
  if (pp < 0 && !p)
    printf("4");
  else {
    pp = pp < 0 ? 0 : pp;
    t = 10 * pp + p;
    printf("%d", (1 + r2[(t + 3) % 4] + r3[(t + 3) % 4] + r4[(t + 1) % 2]) % 5);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    0xebc(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb9(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xeb3(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xead(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x0,%rax
jle    119f <main+0x7f>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1174 <main+0x54>
cmpl   $0x0,-0x10(%rbp)
jge    11c6 <main+0xa6>
cmpl   $0x0,-0xc(%rbp)
jne    11c6 <main+0xa6>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1256 <main+0x136>
cmpl   $0x0,-0x10(%rbp)
jge    11da <main+0xba>
xor    %eax,%eax
mov    %eax,-0x4c(%rbp)
jmp    11e0 <main+0xc0>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
mov    %eax,-0x10(%rbp)
imul   $0xa,-0x10(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x30(%rbp,%rax,4),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
mov    -0x14(%rbp),%eax
add    $0x3,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x54(%rbp),%eax
movslq %edx,%rcx
add    -0x40(%rbp,%rcx,4),%eax
mov    %eax,-0x50(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    -0x50(%rbp),%eax
movslq %edx,%rcx
add    -0x48(%rbp,%rcx,4),%eax
mov    $0x5,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xeea(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
test   %rax,%rax
jle    118d <main+0x5d>
mov    $0xffffffff,%ebx
lea    0xecf(%rip),%r14
lea    0x4(%rsp),%r15
xchg   %ax,%ax
mov    %ebx,%ebp
mov    0x4(%rsp),%ebx
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
test   %rax,%rax
jg     1160 <main+0x30>
test   %ebp,%ebp
jns    1194 <main+0x64>
test   %ebx,%ebx
jne    1194 <main+0x64>
mov    $0x34,%edi
call   1030 <putchar@plt>
jmp    1220 <main+0xf0>
mov    $0xffffffff,%eax
jmp    11a1 <main+0x71>
xor    %eax,%eax
test   %ebp,%ebp
cmovns %ebp,%eax
lea    (%rax,%rax,4),%eax
lea    (%rbx,%rax,2),%eax
lea    0x3(%rax),%ecx
lea    0x6(%rax),%edx
test   %ecx,%ecx
cmovns %ecx,%edx
and    $0xfffffffc,%edx
neg    %edx
lea    (%rax,%rdx,1),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
lea    0xe3f(%rip),%rdx
mov    (%rdx,%rcx,4),%edx
lea    0xe45(%rip),%rsi
add    (%rsi,%rcx,4),%edx
mov    %eax,%ecx
add    $0x1,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
add    $0x1,%ecx
and    $0xfffffffe,%ecx
neg    %ecx
add    %ecx,%eax
add    $0x1,%eax
cltq
lea    0xe32(%rip),%rcx
mov    (%rcx,%rax,4),%eax
add    %edx,%eax
add    $0x1,%eax
movslq %eax,%rsi
imul   $0x66666667,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x21,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
lea    0xe13(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.r2 = [4 x i32] [i32 2, i32 4, i32 8, i32 6]
@__const.main.r3 = [4 x i32] [i32 3, i32 9, i32 7, i32 1]
@__const.main.r4 = [2 x i32] [i32 4, i32 6]
@.str = [4 x i8] c"%1d\00"
@.str.1 = [2 x i8] c"4\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [4 x i32]
%7 = alloca [4 x i32]
%8 = alloca [2 x i32]
store i32 0, i32* %1
store i32 -1, i32* %3
store i32 -1, i32* %4
%9 = bitcast [4 x i32]* %6 to i8*
%10 = bitcast [4 x i32]* %7 to i8*
%11 = bitcast [2 x i32]* %8 to i8*
br label %12
12: ; preds = %15, %0
%13 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load i32, i32* %3
store i32 %16, i32* %4
%17 = load i32, i32* %2
store i32 %17, i32* %3
br label %12
18: ; preds = %12
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %61
26: ; preds = %21, %18
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
br label %32
30: ; preds = %26
%31 = load i32, i32* %4
br label %32
32: ; preds = %30, %29
%33 = phi i32 [ 0, %29 ], [ %31, %30 ]
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = mul nsw i32 10, %34
%36 = load i32, i32* %3
%37 = add nsw i32 %35, %36
store i32 %37, i32* %5
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 3
%40 = srem i32 %39, 4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = add nsw i32 1, %43
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 3
%47 = srem i32 %46, 4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = add nsw i32 %44, %50
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
%54 = srem i32 %53, 2
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 %55
%57 = load i32, i32* %56
%58 = add nsw i32 %51, %57
%59 = srem i32 %58, 5
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %32, %24
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@__const.main.r2 = [4 x i32] [i32 2, i32 4, i32 8, i32 6]
@__const.main.r3 = [4 x i32] [i32 3, i32 9, i32 7, i32 1]
@__const.main.r4 = [2 x i32] [i32 4, i32 6]
@.str = [4 x i8] c"%1d\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp sgt i64 %3, 0
br i1 %4, label %5, label %21
5: ; preds = %0, %5
%6 = phi i32 [ %7, %5 ], [ -1, %0 ]
%7 = load i32, i32* %1
%8 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %5, label %10
10: ; preds = %5
%11 = icmp sgt i32 %6, -1
%12 = icmp ne i32 %7, 0
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 @putchar(i32 52)
br label %40
16: ; preds = %10
%17 = icmp sgt i32 %6, 0
%18 = select i1 %17, i32 %6, i32 0
%19 = mul i32 %18, 10
%20 = add nsw i32 %19, %7
br label %21
21: ; preds = %16, %0
%22 = phi i32 [ %20, %16 ], [ -1, %0 ]
%23 = add nsw i32 %22, 3
%24 = srem i32 %23, 4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [4 x i32], [4 x i32]* @__const.main.r2, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
%29 = getelementptr inbounds [4 x i32], [4 x i32]* @__const.main.r3, i64 0, i64 %25
%30 = load i32, i32* %29
%31 = add nsw i32 %28, %30
%32 = add nsw i32 %22, 1
%33 = srem i32 %32, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [2 x i32], [2 x i32]* @__const.main.r4, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = add nsw i32 %31, %36
%38 = srem i32 %37, 5
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %21, %14
ret i32 0
}