#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 *, ...);
int /*<<< orphan*/ scanf(char *, int *);
main() {
  int ans = 0, x, y, div;
  printf("\nread div:");
  scanf("%d", &div);
  printf("\nread x:");
  scanf("%d", &x);
  if (x % div == 0) {
    ans = x / div;
  } else {
    while (x % div != 0) {
      ans = ans * 10 + x / div;
      x = x % div;
      printf("\nread y:");
      scanf("%d", &y);
      x = x * 10 + y;
    }
    ans = ans * 10 + x / div;
  }
  printf("\nans=%d", ans);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed7(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeb9(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
jne    1191 <main+0x71>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x8(%rbp)
jmp    120d <main+0xed>
jmp    1196 <main+0x76>
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
cmp    $0x0,%edx
je     11f5 <main+0xd5>
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0xc(%rbp)
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe45(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
imul   $0xa,-0xc(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1196 <main+0x76>
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xece(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee2(%rip),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
lea    0xeb7(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <scanf@plt>
mov    0xc(%rsp),%ecx
mov    0x10(%rsp),%r8d
mov    %ecx,%eax
cltd
idiv   %r8d
test   %edx,%edx
je     11ec <main+0xcc>
mov    %edx,%esi
lea    0xe90(%rip),%r14
lea    0xe97(%rip),%r15
lea    0x14(%rsp),%r12
xor    %edi,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%eax
cltd
idiv   %r8d
mov    %eax,%ebx
add    %edi,%ebx
mov    %esi,0xc(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <scanf@plt>
mov    0xc(%rsp),%eax
lea    (%rax,%rax,4),%ecx
add    %ecx,%ecx
add    0x14(%rsp),%ecx
mov    %ecx,0xc(%rsp)
mov    0x10(%rsp),%r8d
mov    %ecx,%eax
cltd
idiv   %r8d
mov    %edx,%esi
add    %ebx,%ebx
lea    (%rbx,%rbx,4),%edi
test   %edx,%edx
jne    11a0 <main+0x80>
add    %edi,%eax
lea    0xe2a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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