#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 */
scalar_t__ isdigit(char);
int get_episode(const char *s) {
  char c;
  int count = 0;
  int episode = 0;
  while ((c = *(s++)) != '\0') {
    if (isdigit(c)) {
      count++;
      episode = episode * 10 + (c - '0');
    } else {
      episode = count = 0;
    }
    if (count == 3)
      return episode;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_episode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11a3 <get_episode+0x93>
movsbl -0x11(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     117b <get_episode+0x6b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
imul   $0xa,-0x1c(%rbp),%eax
movsbl -0x11(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    1189 <get_episode+0x79>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x18(%rbp)
jne    119e <get_episode+0x8e>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11aa <get_episode+0x9a>
jmp    112a <get_episode+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_episode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %r12d,%r12d
xor    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl (%r14),%r15d
test   %r15d,%r15d
je     1162 <get_episode+0x52>
add    $0x1,%r14
mov    %r15d,%edi
call   1030 <isdigit@plt>
add    $0x1,%ebp
test   %rax,%rax
lea    (%rbx,%rbx,4),%eax
cmove  %r12d,%ebp
lea    -0x30(%r15,%rax,2),%ebx
cmove  %r12d,%ebx
cmp    $0x3,%ebp
jne    1130 <get_episode+0x20>
jmp    1164 <get_episode+0x54>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_episode(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %32, %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i32 1
store i8* %9, i8** %3
%10 = load i8, i8* %8
store i8 %10, i8* %4
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %7
%14 = load i8, i8* %4
%15 = call i64 @isdigit(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %13
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
%20 = load i32, i32* %6
%21 = mul nsw i32 %20, 10
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = sub nsw i32 %23, 48
%25 = add nsw i32 %21, %24
store i32 %25, i32* %6
br label %27
26: ; preds = %13
store i32 0, i32* %5
store i32 0, i32* %6
br label %27
27: ; preds = %26, %17
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 3
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i32, i32* %6
store i32 %31, i32* %2
br label %34
32: ; preds = %27
br label %7
33: ; preds = %7
store i32 0, i32* %2
br label %34
34: ; preds = %33, %30
%35 = load i32, i32* %2
ret i32 %35
}

LLVM IR (-O2):
define i32 @get_episode(i8* nocapture %0) {
br label %2
2: ; preds = %8, %1
%3 = phi i8* [ %0, %1 ], [ %10, %8 ]
%4 = phi i32 [ 0, %1 ], [ %17, %8 ]
%5 = phi i32 [ 0, %1 ], [ %18, %8 ]
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %2
%9 = sext i8 %6 to i32
%10 = getelementptr inbounds i8, i8* %3, i64 1
%11 = tail call i64 @isdigit(i8 signext %6)
%12 = icmp eq i64 %11, 0
%13 = add nsw i32 %4, 1
%14 = mul nsw i32 %5, 10
%15 = add i32 %14, -48
%16 = add i32 %15, %9
%17 = select i1 %12, i32 0, i32 %13
%18 = select i1 %12, i32 0, i32 %16
%19 = icmp eq i32 %17, 3
br i1 %19, label %20, label %2
20: ; preds = %2, %8
%21 = phi i32 [ %18, %8 ], [ 0, %2 ]
ret i32 %21
}