#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 strlen(char *);
int positionOfFirstNonDigit(char *name) {
  int i, j, len, flag;
  const char digits[] = "0123456789";
  len = strlen(name);
  flag = 1;
  i = 0;
  while ((i < len) && flag) {
    flag = 0;
    for (j = 0; j < 10; j++) {
      if (name[i] == digits[j])
        flag = 1;
    }
    i++;
  }
  return i;
}


x86 assembly (clang, -O0):
<positionOfFirstNonDigit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xedd(%rip),%rax
mov    %rax,-0x23(%rbp)
mov    0xeda(%rip),%ax
mov    %ax,-0x1b(%rbp)
mov    0xed2(%rip),%al
mov    %al,-0x19(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x24(%rbp)
jge    1170 <positionOfFirstNonDigit+0x60>
cmpl   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x24(%rbp)
mov    -0x24(%rbp),%al
test   $0x1,%al
jne    1180 <positionOfFirstNonDigit+0x70>
jmp    11dd <positionOfFirstNonDigit+0xcd>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    11cf <positionOfFirstNonDigit+0xbf>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movslq -0x10(%rbp),%rcx
movsbl -0x23(%rbp,%rcx,1),%ecx
cmp    %ecx,%eax
jne    11bc <positionOfFirstNonDigit+0xac>
movl   $0x1,-0x18(%rbp)
jmp    11c1 <positionOfFirstNonDigit+0xb1>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118e <positionOfFirstNonDigit+0x7e>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1155 <positionOfFirstNonDigit+0x45>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<positionOfFirstNonDigit>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    1160 <positionOfFirstNonDigit+0x50>
mov    %eax,%esi
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r14,%rax,1),%ecx
mov    %ecx,%edx
and    $0xfe,%dl
cmp    $0x30,%dl
sete   %dl
cmp    $0x32,%cl
sete   %bl
add    $0xcd,%cl
cmp    $0x7,%cl
setb   %cl
add    $0x1,%rax
cmp    %rsi,%rax
jae    1162 <positionOfFirstNonDigit+0x52>
or     %dl,%bl
or     %bl,%cl
jne    1130 <positionOfFirstNonDigit+0x20>
jmp    1162 <positionOfFirstNonDigit+0x52>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @positionOfFirstNonDigit(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %22
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %17, %6 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = and i8 %9, -2
%11 = icmp eq i8 %10, 48
%12 = icmp eq i8 %9, 50
%13 = or i1 %12, %11
%14 = add i8 %9, -51
%15 = icmp ult i8 %14, 7
%16 = select i1 %15, i1 true, i1 %13
%17 = add nuw nsw i64 %7, 1
%18 = icmp ult i64 %17, %5
%19 = select i1 %18, i1 %16, i1 false
br i1 %19, label %6, label %20
20: ; preds = %6
%21 = trunc i64 %17 to i32
br label %22
22: ; preds = %20, %1
%23 = phi i32 [ 0, %1 ], [ %21, %20 ]
ret i32 %23
}