#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 count_digits(int);
int first_two_digits(int n) {
  int digit = n % 10;
  if (n <= 0)
    return 0;
  if (((count_digits(n)) == 2) || ((count_digits(n)) == 1))
    return digit + first_two_digits(n / 10);
  else
    return first_two_digits(n / 10);
}


x86 assembly (clang, -O0):
<first_two_digits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     114f <first_two_digits+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    11ad <first_two_digits+0x8d>
mov    -0x8(%rbp),%edi
call   1030 <count_digits@plt>
cmp    $0x2,%eax
je     1171 <first_two_digits+0x51>
mov    -0x8(%rbp),%edi
call   1030 <count_digits@plt>
cmp    $0x1,%eax
jne    1198 <first_two_digits+0x78>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <first_two_digits@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <first_two_digits+0x8d>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   1040 <first_two_digits@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<first_two_digits>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    117b <first_two_digits+0x6b>
mov    %edi,%ebx
xor    %r14d,%r14d
mov    $0xcccccccd,%r15d
jmp    114a <first_two_digits+0x3a>
nopl   0x0(%rax,%rax,1)
imul   %r15,%rbx
shr    $0x23,%rbx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %ebp,%ecx
sub    %eax,%ecx
add    %ecx,%r14d
cmp    $0xa,%ebp
jb     117e <first_two_digits+0x6e>
mov    %ebx,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
call   1030 <count_digits@plt>
mov    %ebp,%ebx
cmp    $0x2,%eax
je     1130 <first_two_digits+0x20>
mov    %ebp,%edi
call   1030 <count_digits@plt>
cmp    $0x1,%eax
je     1130 <first_two_digits+0x20>
imul   %r15,%rbx
shr    $0x23,%rbx
cmp    $0x9,%ebp
mov    %ebx,%ebp
ja     1150 <first_two_digits+0x40>
jmp    117e <first_two_digits+0x6e>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @first_two_digits(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = srem i32 %5, 10
store i32 %6, i32* %4
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 0, i32* %2
br label %28
10: ; preds = %1
%11 = load i32, i32* %3
%12 = call i32 @count_digits(i32 %11)
%13 = icmp eq i32 %12, 2
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i32, i32* %3
%16 = call i32 @count_digits(i32 %15)
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %24
18: ; preds = %14, %10
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = sdiv i32 %20, 10
%22 = call i32 @first_two_digits(i32 %21)
%23 = add nsw i32 %19, %22
store i32 %23, i32* %2
br label %28
24: ; preds = %14
%25 = load i32, i32* %3
%26 = sdiv i32 %25, 10
%27 = call i32 @first_two_digits(i32 %26)
store i32 %27, i32* %2
br label %28
28: ; preds = %24, %18, %9
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @first_two_digits(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %21, label %3
3: ; preds = %1, %13
%4 = phi i32 [ %15, %13 ], [ %0, %1 ]
%5 = phi i32 [ %16, %13 ], [ 0, %1 ]
br label %6
6: ; preds = %3, %18
%7 = phi i32 [ %4, %3 ], [ %19, %18 ]
%8 = tail call i32 @count_digits(i32 %7)
%9 = icmp eq i32 %8, 2
br i1 %9, label %13, label %10
10: ; preds = %6
%11 = tail call i32 @count_digits(i32 %7)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %18
13: ; preds = %10, %6
%14 = urem i32 %7, 10
%15 = udiv i32 %7, 10
%16 = add nuw nsw i32 %14, %5
%17 = icmp ult i32 %7, 10
br i1 %17, label %21, label %3
18: ; preds = %10
%19 = udiv i32 %7, 10
%20 = icmp ult i32 %7, 10
br i1 %20, label %21, label %6
21: ; preds = %13, %18, %1
%22 = phi i32 [ 0, %1 ], [ %5, %18 ], [ %16, %13 ]
ret i32 %22
}