#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 */
char *strchr(char const *, char);
char *strrchr(char const *, char);
int strtol(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int optstr_frames_needed(const char *filter_desc, int *needed_frames) {
  const char *s = NULL;
  if ((s = strrchr(filter_desc, ',')) == NULL) {
    return 1;
  }
  if ((s = strchr(s, '\"')) == NULL) {
    return 1;
  }
  *needed_frames = strtol(s + 1, NULL, 0);
  return 0;
}


x86 assembly (clang, -O0):
<optstr_frames_needed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1170 <optstr_frames_needed+0x40>
movl   $0x1,-0x4(%rbp)
jmp    11ba <optstr_frames_needed+0x8a>
mov    -0x20(%rbp),%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1198 <optstr_frames_needed+0x68>
movl   $0x1,-0x4(%rbp)
jmp    11ba <optstr_frames_needed+0x8a>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optstr_frames_needed>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    $0x2c,%esi
call   1040 <strrchr@plt>
mov    $0x1,%ebx
test   %rax,%rax
je     1172 <optstr_frames_needed+0x42>
mov    %rax,%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1172 <optstr_frames_needed+0x42>
add    $0x1,%rax
xor    %ebx,%ebx
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %eax,(%r14)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @optstr_frames_needed(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* null, i8** %6
%7 = load i8*, i8** %4
%8 = call i8* @strrchr(i8* %7, i8 signext 44)
store i8* %8, i8** %6
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 1, i32* %3
br label %21
11: ; preds = %2
%12 = load i8*, i8** %6
%13 = call i8* @strchr(i8* %12, i8 signext 34)
store i8* %13, i8** %6
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %16
15: ; preds = %11
store i32 1, i32* %3
br label %21
16: ; preds = %11
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = call i32 @strtol(i8* %18, i32* null, i32 0)
%20 = load i32*, i32** %5
store i32 %19, i32* %20
store i32 0, i32* %3
br label %21
21: ; preds = %16, %15, %10
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
define i32 @optstr_frames_needed(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 44)
%4 = icmp eq i8* %3, null
br i1 %4, label %11, label %5
5: ; preds = %2
%6 = tail call i8* @strchr(i8* %3, i8 signext 34)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = tail call i32 @strtol(i8* nocapture %9, i32* null, i32 0)
store i32 %10, i32* %1
br label %11
11: ; preds = %5, %2, %8
%12 = phi i32 [ 0, %8 ], [ 1, %2 ], [ 1, %5 ]
ret i32 %12
}