#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 *);
scalar_t__ strstr(char *, char *);
int get_record_num(char **ptr, int matchedrec) {
  int i;
  int recnum = -1;
  for (i = matchedrec; i >= 0; --i) {
    if (strstr(*(ptr + i), "%%")) {
      recnum = atoi(*(ptr + i));
      break;
    }
  }
  if (recnum >= 0)
    return recnum;
  else
    return -1;
}


x86 assembly (clang, -O0):
<get_record_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1194 <get_record_num+0x74>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xea7(%rip),%rsi
call   1040 <strstr@plt>
cmp    $0x0,%rax
je     1181 <get_record_num+0x61>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    1194 <get_record_num+0x74>
jmp    1186 <get_record_num+0x66>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    113c <get_record_num+0x1c>
cmpl   $0x0,-0x1c(%rbp)
jl     11a9 <get_record_num+0x89>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b0 <get_record_num+0x90>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_record_num>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
test   %esi,%esi
js     1176 <get_record_num+0x56>
mov    %rdi,%rbx
mov    %esi,%ebp
lea    0xec3(%rip),%r15
nopl   (%rax)
mov    (%rbx,%rbp,8),%rdi
mov    %r15,%rsi
call   1040 <strstr@plt>
test   %rax,%rax
jne    115f <get_record_num+0x3f>
lea    -0x1(%rbp),%rax
test   %rbp,%rbp
mov    %rax,%rbp
jg     1140 <get_record_num+0x20>
jmp    1176 <get_record_num+0x56>
mov    %ebp,%eax
mov    (%rbx,%rax,8),%rdi
call   1030 <atoi@plt>
test   %eax,%eax
mov    $0xffffffff,%r14d
cmovns %eax,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%%\00"
define i32 @get_record_num(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i32 -1, i32* %7
%8 = load i32, i32* %5
store i32 %8, i32* %6
br label %9
9: ; preds = %28, %2
%10 = load i32, i32* %6
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %31
12: ; preds = %9
%13 = load i8**, i8*** %4
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i64 @strstr(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %12
%21 = load i8**, i8*** %4
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %21, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %7
br label %31
27: ; preds = %12
br label %28
28: ; preds = %27
%29 = load i32, i32* %6
%30 = add nsw i32 %29, -1
store i32 %30, i32* %6
br label %9
31: ; preds = %20, %9
%32 = load i32, i32* %7
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = load i32, i32* %7
store i32 %35, i32* %3
br label %37
36: ; preds = %31
store i32 -1, i32* %3
br label %37
37: ; preds = %36, %34
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"%%\00"
define i32 @get_record_num(i8** nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, -1
br i1 %3, label %4, label %22
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %12
%7 = phi i64 [ %5, %4 ], [ %13, %12 ]
%8 = getelementptr inbounds i8*, i8** %0, i64 %7
%9 = load i8*, i8** %8
%10 = tail call i64 @strstr(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %6
%13 = add nsw i64 %7, -1
%14 = icmp sgt i64 %7, 0
br i1 %14, label %6, label %22
15: ; preds = %6
%16 = and i64 %7, 4294967295
%17 = getelementptr inbounds i8*, i8** %0, i64 %16
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = icmp sgt i32 %19, -1
%21 = select i1 %20, i32 %19, i32 -1
br label %22
22: ; preds = %12, %2, %15
%23 = phi i32 [ %21, %15 ], [ -1, %2 ], [ -1, %12 ]
ret i32 %23
}