#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 atoi(char const *);
scalar_t__ isdigit(unsigned char);
scalar_t__ strcmp(char const *, char *);
int strlen(char const *);
int get_instance(const char *name) {
  const char *cp, *endcp;
  int n;
  if (strcmp(name, "any") == 0) {
    return 2147483647;
  }
  endcp = name + strlen(name);
  for (cp = name; cp < endcp && !isdigit((unsigned char)*cp); ++cp)
    continue;
  if (isdigit((unsigned char)*cp))
    n = atoi(cp);
  else
    n = 0;
  return (n);
}


x86 assembly (clang, -O0):
<get_instance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1172 <get_instance+0x32>
movl   $0x7fffffff,-0x4(%rbp)
jmp    1220 <get_instance+0xe0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    -0x20(%rbp),%rcx
mov    %al,-0x31(%rbp)
jae    11c6 <get_instance+0x86>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11d6 <get_instance+0x96>
jmp    11ec <get_instance+0xac>
jmp    11db <get_instance+0x9b>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    119b <get_instance+0x5b>
mov    -0x18(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1213 <get_instance+0xd3>
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    121a <get_instance+0xda>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_instance>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xeb2(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11a2 <get_instance+0x62>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1186 <get_instance+0x46>
movslq %eax,%r14
add    %rbx,%r14
nopw   0x0(%rax,%rax,1)
movzbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1186 <get_instance+0x46>
add    $0x1,%rbx
cmp    %r14,%rbx
jb     1170 <get_instance+0x30>
movzbl (%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11a9 <get_instance+0x69>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <atoi@plt>
mov    $0x7fffffff,%eax
jmp    11ab <get_instance+0x6b>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"any\00"
define i32 @get_instance(i8* %0) {
%2 = tail call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %24, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = icmp sgt i32 %5, 0
br i1 %8, label %9, label %17
9: ; preds = %4, %14
%10 = phi i8* [ %15, %14 ], [ %0, %4 ]
%11 = load i8, i8* %10
%12 = tail call i64 @isdigit(i8 zeroext %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %10, i64 1
%16 = icmp ult i8* %15, %7
br i1 %16, label %9, label %17
17: ; preds = %9, %14, %4
%18 = phi i8* [ %0, %4 ], [ %15, %14 ], [ %10, %9 ]
%19 = load i8, i8* %18
%20 = tail call i64 @isdigit(i8 zeroext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %17
%23 = tail call i32 @atoi(i8* %18)
br label %24
24: ; preds = %22, %17, %1
%25 = phi i32 [ 2147483647, %1 ], [ %23, %22 ], [ 0, %17 ]
ret i32 %25
}