#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__ strcmp(char *, char *);
size_t strlen(char *);
scalar_t__ strncmp(char *, char *, size_t);
int same_pref_name(char *s, char *item) {
  if ((!s) || (!item))
    return 3;
  if (strcmp(s, item) == 0)
    return 0;
  else {
    if ((strncmp(s, item, strlen(item)) == 0) && (s[strlen(item)] == '_'))
      return 1;
  }
  return 2;
}


x86 assembly (clang, -O0):
<same_pref_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <same_pref_name+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1162 <same_pref_name+0x32>
movl   $0x3,-0x4(%rbp)
jmp    11f5 <same_pref_name+0xc5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1185 <same_pref_name+0x55>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <same_pref_name+0xc5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11e9 <same_pref_name+0xb9>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
jne    11e9 <same_pref_name+0xb9>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <same_pref_name+0xc5>
jmp    11ee <same_pref_name+0xbe>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<same_pref_name>:
push   %r14
push   %rbx
push   %rax
mov    $0x3,%eax
test   %rdi,%rdi
je     1191 <same_pref_name+0x61>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1191 <same_pref_name+0x61>
mov    %rdi,%r14
mov    %rbx,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     118f <same_pref_name+0x5f>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1188 <same_pref_name+0x58>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    $0x1,%eax
cmpb   $0x5f,(%r14,%rcx,1)
je     1191 <same_pref_name+0x61>
mov    $0x2,%eax
jmp    1191 <same_pref_name+0x61>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @same_pref_name(i8* %0, i8* %1) {
%3 = icmp ne i8* %0, null
%4 = icmp ne i8* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = tail call i64 @strcmp(i8* %0, i8* %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %6
%10 = tail call i64 @strlen(i8* %1)
%11 = tail call i64 @strncmp(i8* %0, i8* %1, i64 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = tail call i64 @strlen(i8* %1)
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 95
br i1 %17, label %19, label %18
18: ; preds = %9, %13
br label %19
19: ; preds = %13, %6, %2, %18
%20 = phi i32 [ 2, %18 ], [ 3, %2 ], [ 0, %6 ], [ 1, %13 ]
ret i32 %20
}