#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, char *, int *);
int strlen(char *);
int main(int argc, char **argv) {
  int i, a, len, ans = 0;
  char string[0xfffff];
  memset(string, '0', 0xfffff);
  scanf("%s%d", string, &a);
  for (i = 0; i < strlen(string); i++)
    ans = (int)(((long long)ans * 10 + string[i] - '0') % a);
  printf("%d", ans);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x100020(%rbp),%rdi
mov    $0x30,%esi
mov    $0xfffff,%edx
call   1050 <memset@plt>
lea    -0x100020(%rbp),%rsi
lea    0xe7c(%rip),%rdi
lea    -0x18(%rbp),%rdx
call   1060 <scanf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x100024(%rbp)
lea    -0x100020(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x100024(%rbp),%eax
cmp    %ecx,%eax
jge    11f1 <main+0xb1>
movslq -0x20(%rbp),%rax
imul   $0xa,%rax,%rax
movslq -0x14(%rbp),%rcx
movsbq -0x100020(%rbp,%rcx,1),%rcx
ef ff
add    %rcx,%rax
sub    $0x30,%rax
movslq -0x18(%rbp),%rcx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1194 <main+0x54>
mov    -0x20(%rbp),%esi
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x100030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100010,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x30,%esi
mov    $0xfffff,%edx
call   1050 <memset@plt>
lea    0xe96(%rip),%rdi
lea    0xc(%rsp),%rdx
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
jle    11dd <main+0x9d>
lea    0x10(%rsp),%r14
xor    %r15d,%r15d
jmp    11ab <main+0x6b>
nop
cqto
idiv   %rcx
mov    %rdx,%r15
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11da <main+0x9a>
movslq %r15d,%rax
lea    (%rax,%rax,4),%rax
movsbq 0x10(%rsp,%rbx,1),%rcx
lea    (%rcx,%rax,2),%rax
add    $0xffffffffffffffd0,%rax
movslq 0xc(%rsp),%rcx
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
jne    1190 <main+0x50>
xor    %edx,%edx
div    %ecx
mov    %edx,%r15d
jmp    1198 <main+0x58>
mov    %r15d,%ebx
lea    0xe1e(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x100010,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [3 x i8] c"%d\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 [1048575 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%11 = getelementptr inbounds [1048575 x i8], [1048575 x i8]* %10, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 48, i32 1048575)
%13 = getelementptr inbounds [1048575 x i8], [1048575 x i8]* %10, i64 0, i64 0
%14 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %13, i32* %7)
store i32 0, i32* %6
br label %15
15: ; preds = %35, %2
%16 = load i32, i32* %6
%17 = getelementptr inbounds [1048575 x i8], [1048575 x i8]* %10, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = icmp slt i32 %16, %18
br i1 %19, label %20, label %38
20: ; preds = %15
%21 = load i32, i32* %9
%22 = sext i32 %21 to i64
%23 = mul nsw i64 %22, 10
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [1048575 x i8], [1048575 x i8]* %10, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i64
%29 = add nsw i64 %23, %28
%30 = sub nsw i64 %29, 48
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = srem i64 %30, %32
%34 = trunc i64 %33 to i32
store i32 %34, i32* %9
br label %35
35: ; preds = %20
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %15
38: ; preds = %15
%39 = load i32, i32* %9
%40 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca [1048575 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [1048575 x i8], [1048575 x i8]* %4, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i32 48, i32 1048575)
%8 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %6, i32* %3)
%9 = call i32 @strlen(i8* %6)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %2, %11
%12 = phi i64 [ %25, %11 ], [ 0, %2 ]
%13 = phi i64 [ %24, %11 ], [ 0, %2 ]
%14 = shl i64 %13, 32
%15 = ashr exact i64 %14, 32
%16 = mul nsw i64 %15, 10
%17 = getelementptr inbounds [1048575 x i8], [1048575 x i8]* %4, i64 0, i64 %12
%18 = load i8, i8* %17
%19 = sext i8 %18 to i64
%20 = add nsw i64 %16, -48
%21 = add nsw i64 %20, %19
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = srem i64 %21, %23
%25 = add nuw nsw i64 %12, 1
%26 = call i32 @strlen(i8* %6)
%27 = sext i32 %26 to i64
%28 = icmp slt i64 %25, %27
br i1 %28, label %11, label %29
29: ; preds = %11
%30 = trunc i64 %24 to i32
br label %31
31: ; preds = %29, %2
%32 = phi i32 [ %30, %29 ], [ 0, %2 ]
%33 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %32)
ret i32 0
}