#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 *strcasestr(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *rm_realm_prefix(char *from, char *dst, int type) {
  int slen;
  slen = strlen(from);
  if (slen < 5)
    strcpy(dst, from);
  else if (type == 12) {
    if (strcasestr(from, "INT.") == from || strcasestr(from, "NTK.") == from)
      strcpy(dst, from + 4);
    else
      strcpy(dst, from);
  } else if (strcasestr(from + slen - 4, ".INT") ||
             strcasestr(from + slen - 4, ".NTK")) {
    strncpy(dst, from, slen - 4);
    dst[slen - 4] = 0;
  } else
    strcpy(dst, from);
  return dst;
}


x86 assembly (clang, -O0):
<rm_realm_prefix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    117b <rm_realm_prefix+0x3b>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    126b <rm_realm_prefix+0x12b>
cmpl   $0xc,-0x14(%rbp)
jne    11e1 <rm_realm_prefix+0xa1>
mov    -0x8(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strcasestr@plt>
cmp    -0x8(%rbp),%rax
je     11b9 <rm_realm_prefix+0x79>
mov    -0x8(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1060 <strcasestr@plt>
cmp    -0x8(%rbp),%rax
jne    11cf <rm_realm_prefix+0x8f>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
add    $0x4,%rsi
call   1040 <strcpy@plt>
jmp    11dc <rm_realm_prefix+0x9c>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1266 <rm_realm_prefix+0x126>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe13(%rip),%rsi
call   1060 <strcasestr@plt>
cmp    $0x0,%rax
jne    122b <rm_realm_prefix+0xeb>
mov    -0x8(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xdf3(%rip),%rsi
call   1060 <strcasestr@plt>
cmp    $0x0,%rax
je     1254 <rm_realm_prefix+0x114>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%edx
sub    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
sub    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1261 <rm_realm_prefix+0x121>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1266 <rm_realm_prefix+0x126>
jmp    126b <rm_realm_prefix+0x12b>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm_realm_prefix>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
cmp    $0x4,%eax
jle    11d8 <rm_realm_prefix+0x98>
cmp    $0xc,%ebp
jne    118d <rm_realm_prefix+0x4d>
lea    0xe9a(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcasestr@plt>
cmp    %r15,%rax
je     1187 <rm_realm_prefix+0x47>
lea    0xe8b(%rip),%rsi
mov    %r15,%rdi
call   1060 <strcasestr@plt>
cmp    %r15,%rax
jne    11d8 <rm_realm_prefix+0x98>
add    $0x4,%r15
jmp    11d8 <rm_realm_prefix+0x98>
mov    %eax,%ebx
mov    %eax,%eax
lea    (%r15,%rax,1),%r12
add    $0xfffffffffffffffc,%r12
lea    0xe6a(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcasestr@plt>
test   %rax,%rax
jne    11c1 <rm_realm_prefix+0x81>
lea    0xe5b(%rip),%rsi
mov    %r12,%rdi
call   1060 <strcasestr@plt>
test   %rax,%rax
je     11d8 <rm_realm_prefix+0x98>
add    $0xfffffffc,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r14,%rbx,1)
jmp    11e3 <rm_realm_prefix+0xa3>
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"INT.\00"
@.str.1 = [5 x i8] c"NTK.\00"
@.str.2 = [5 x i8] c".INT\00"
@.str.3 = [5 x i8] c".NTK\00"
define i8* @rm_realm_prefix(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 5
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i8*, i8** %4
%15 = call i32 @strcpy(i8* %13, i8* %14)
br label %72
16: ; preds = %3
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, 12
br i1 %18, label %19, label %39
19: ; preds = %16
%20 = load i8*, i8** %4
%21 = call i8* @strcasestr(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%22 = load i8*, i8** %4
%23 = icmp eq i8* %21, %22
br i1 %23, label %29, label %24
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = call i8* @strcasestr(i8* %25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = load i8*, i8** %4
%28 = icmp eq i8* %26, %27
br i1 %28, label %29, label %34
29: ; preds = %24, %19
%30 = load i8*, i8** %5
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 4
%33 = call i32 @strcpy(i8* %30, i8* %32)
br label %38
34: ; preds = %24
%35 = load i8*, i8** %5
%36 = load i8*, i8** %4
%37 = call i32 @strcpy(i8* %35, i8* %36)
br label %38
38: ; preds = %34, %29
br label %71
39: ; preds = %16
%40 = load i8*, i8** %4
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 -4
%45 = call i8* @strcasestr(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%46 = icmp ne i8* %45, null
br i1 %46, label %55, label %47
47: ; preds = %39
%48 = load i8*, i8** %4
%49 = load i32, i32* %7
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = getelementptr inbounds i8, i8* %51, i64 -4
%53 = call i8* @strcasestr(i8* %52, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%54 = icmp ne i8* %53, null
br i1 %54, label %55, label %66
55: ; preds = %47, %39
%56 = load i8*, i8** %5
%57 = load i8*, i8** %4
%58 = load i32, i32* %7
%59 = sub nsw i32 %58, 4
%60 = call i32 @strncpy(i8* %56, i8* %57, i32 %59)
%61 = load i8*, i8** %5
%62 = load i32, i32* %7
%63 = sub nsw i32 %62, 4
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %61, i64 %64
store i8 0, i8* %65
br label %70
66: ; preds = %47
%67 = load i8*, i8** %5
%68 = load i8*, i8** %4
%69 = call i32 @strcpy(i8* %67, i8* %68)
br label %70
70: ; preds = %66, %55
br label %71
71: ; preds = %70, %38
br label %72
72: ; preds = %71, %12
%73 = load i8*, i8** %5
ret i8* %73
}

LLVM IR (-O2):
@.str = [5 x i8] c"INT.\00"
@.str.1 = [5 x i8] c"NTK.\00"
@.str.2 = [5 x i8] c".INT\00"
@.str.3 = [5 x i8] c".NTK\00"
define i8* @rm_realm_prefix(i8* %0, i8* returned %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp slt i32 %4, 5
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %37
8: ; preds = %3
%9 = icmp eq i32 %2, 12
br i1 %9, label %10, label %21
10: ; preds = %8
%11 = tail call i8* @strcasestr(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, %0
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = tail call i8* @strcasestr(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i8* %14, %0
br i1 %15, label %16, label %19
16: ; preds = %13, %10
%17 = getelementptr inbounds i8, i8* %0, i64 4
%18 = tail call i32 @strcpy(i8* %1, i8* %17)
br label %37
19: ; preds = %13
%20 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %37
21: ; preds = %8
%22 = zext i32 %4 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 -4
%25 = tail call i8* @strcasestr(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = tail call i8* @strcasestr(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i8* %28, null
br i1 %29, label %35, label %30
30: ; preds = %27, %21
%31 = add nsw i32 %4, -4
%32 = tail call i32 @strncpy(i8* %1, i8* %0, i32 %31)
%33 = zext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %1, i64 %33
store i8 0, i8* %34
br label %37
35: ; preds = %27
%36 = tail call i32 @strcpy(i8* %1, i8* %0)
br label %37
37: ; preds = %19, %16, %35, %30, %6
ret i8* %1
}