#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__ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int strtol(char *, char **, int);
int match_str(char *mstr, char *pattern, int *n) {
  char *pend;
  int l;
  if (mstr == NULL || n == NULL || pattern == NULL)
    return 0;
  l = strlen(pattern);
  if (!strncmp(mstr, pattern, l)) {
    *n = strtol(mstr + l, &pend, 10);
    if (pend == NULL)
      return 0;
    if (strlen(pend) > 0)
      return 0;
  } else
    return 0;
  return -1;
}


x86 assembly (clang, -O0):
<match_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1165 <match_str+0x35>
cmpq   $0x0,-0x20(%rbp)
je     1165 <match_str+0x35>
cmpq   $0x0,-0x18(%rbp)
jne    1171 <match_str+0x41>
movl   $0x0,-0x4(%rbp)
jmp    1205 <match_str+0xd5>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11f2 <match_str+0xc2>
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
add    %rax,%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    11ce <match_str+0x9e>
movl   $0x0,-0x4(%rbp)
jmp    1205 <match_str+0xd5>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%rax
jle    11ed <match_str+0xbd>
movl   $0x0,-0x4(%rbp)
jmp    1205 <match_str+0xd5>
jmp    11fe <match_str+0xce>
movl   $0x0,-0x4(%rbp)
jmp    1205 <match_str+0xd5>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_str>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %r15d,%r15d
test   %rsi,%rsi
je     11ab <match_str+0x7b>
mov    %rdi,%rbx
test   %rdi,%rdi
je     11ab <match_str+0x7b>
mov    %rdx,%r14
test   %rdx,%rdx
je     11ab <match_str+0x7b>
mov    %rsi,%rbp
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
jne    11ab <match_str+0x7b>
movslq %r12d,%rax
add    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,(%r14)
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     11ab <match_str+0x7b>
call   1040 <strlen@plt>
xor    %r15d,%r15d
test   %rax,%rax
setle  %r15b
neg    %r15d
mov    %r15d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @match_str(i8* %0, i8* %1, i32* writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = icmp eq i8* %0, null
%7 = icmp eq i32* %2, null
%8 = or i1 %6, %7
%9 = icmp eq i8* %1, null
%10 = or i1 %9, %8
br i1 %10, label %27, label %11
11: ; preds = %3
%12 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%13 = trunc i64 %12 to i32
%14 = tail call i32 @strncmp(i8* %0, i8* %1, i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %11
%17 = shl i64 %12, 32
%18 = ashr exact i64 %17, 32
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = call i32 @strtol(i8* %19, i8** %4, i32 10)
store i32 %20, i32* %2
%21 = load i8*, i8** %4
%22 = icmp eq i8* %21, null
br i1 %22, label %27, label %23
23: ; preds = %16
%24 = tail call i64 @strlen(i8* %21)
%25 = icmp slt i64 %24, 1
%26 = sext i1 %25 to i32
br label %27
27: ; preds = %11, %23, %16, %3
%28 = phi i32 [ 0, %3 ], [ 0, %16 ], [ %26, %23 ], [ 0, %11 ]
ret i32 %28
}