#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__ isvaliddigit(char);
int strlen2(char *);
int extractNumbers(char *phoneNum, int nums[7]) {
  int totalExtracted = 0;
  int i, phoneNumLen;
  char c;
  phoneNumLen = strlen2(phoneNum);
  for (i = 0; i < phoneNumLen; i++) {
    c = phoneNum[i];
    if (isvaliddigit(c)) {
      if (totalExtracted > 7)
        return -1;
      nums[totalExtracted++] = c - 48;
    }
  }
  return totalExtracted;
}


x86 assembly (clang, -O0):
<extractNumbers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen2@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11bc <extractNumbers+0x9c>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%edi
call   1040 <isvaliddigit@plt>
cmp    $0x0,%rax
je     11a9 <extractNumbers+0x89>
cmpl   $0x7,-0x1c(%rbp)
jle    118d <extractNumbers+0x6d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c2 <extractNumbers+0xa2>
movsbl -0x25(%rbp),%edx
sub    $0x30,%edx
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11ae <extractNumbers+0x8e>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114a <extractNumbers+0x2a>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extractNumbers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen2@plt>
test   %eax,%eax
jle    1180 <extractNumbers+0x60>
mov    %eax,%r12d
xor    %ebp,%ebp
xor    %r13d,%r13d
jmp    1159 <extractNumbers+0x39>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbp
cmp    %rbp,%r12
je     118b <extractNumbers+0x6b>
movsbl (%r15,%rbp,1),%ebx
mov    %ebx,%edi
call   1040 <isvaliddigit@plt>
test   %rax,%rax
je     1150 <extractNumbers+0x30>
cmp    $0x7,%r13d
jg     1185 <extractNumbers+0x65>
add    $0xffffffd0,%ebx
movslq %r13d,%rax
add    $0x1,%r13d
mov    %ebx,(%r14,%rax,4)
jmp    1150 <extractNumbers+0x30>
xor    %r13d,%r13d
jmp    118b <extractNumbers+0x6b>
mov    $0xffffffff,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @extractNumbers(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %6
%10 = load i8*, i8** %4
%11 = call i32 @strlen2(i8* %10)
store i32 %11, i32* %8
store i32 0, i32* %7
br label %12
12: ; preds = %39, %2
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %42
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %9
%22 = load i8, i8* %9
%23 = call i64 @isvaliddigit(i8 signext %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %38
25: ; preds = %16
%26 = load i32, i32* %6
%27 = icmp sgt i32 %26, 7
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 -1, i32* %3
br label %44
29: ; preds = %25
%30 = load i8, i8* %9
%31 = sext i8 %30 to i32
%32 = sub nsw i32 %31, 48
%33 = load i32*, i32** %5
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i32, i32* %33, i64 %36
store i32 %32, i32* %37
br label %38
38: ; preds = %29, %16
br label %39
39: ; preds = %38
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %12
42: ; preds = %12
%43 = load i32, i32* %6
store i32 %43, i32* %3
br label %44
44: ; preds = %42, %28
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
define i32 @extractNumbers(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32 @strlen2(i8* %0)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %26
5: ; preds = %2
%6 = zext i32 %3 to i64
br label %7
7: ; preds = %5, %22
%8 = phi i64 [ 0, %5 ], [ %24, %22 ]
%9 = phi i32 [ 0, %5 ], [ %23, %22 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = tail call i64 @isvaliddigit(i8 signext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %7
%15 = icmp sgt i32 %9, 7
br i1 %15, label %26, label %16
16: ; preds = %14
%17 = sext i8 %11 to i32
%18 = add nsw i32 %17, -48
%19 = add nsw i32 %9, 1
%20 = sext i32 %9 to i64
%21 = getelementptr inbounds i32, i32* %1, i64 %20
store i32 %18, i32* %21
br label %22
22: ; preds = %7, %16
%23 = phi i32 [ %19, %16 ], [ %9, %7 ]
%24 = add nuw nsw i64 %8, 1
%25 = icmp eq i64 %24, %6
br i1 %25, label %26, label %7
26: ; preds = %14, %22, %2
%27 = phi i32 [ 0, %2 ], [ %23, %22 ], [ -1, %14 ]
ret i32 %27
}