#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 /*<<< orphan*/ StringCat(char *, char *, int);
int /*<<< orphan*/ StringCpy(char *, char *, int);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int AlgMorphMap(char *in, int len, char *from, char *to, char *out) {
  int lenfrom;
  lenfrom = strlen(from);
  if ((((&in[len - lenfrom])[0] == (from)[0]) &&
       (strcmp((&in[len - lenfrom]), (from)) == 0))) {
    StringCpy(out, in, 128);
    out[len - lenfrom] = '\0';
    StringCat(out, to, 128);
    return (1);
  } else
    return (0);
}


x86 assembly (clang, -O0):
<AlgMorphMap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11ea <AlgMorphMap+0xaa>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
sub    -0x34(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x20(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ea <AlgMorphMap+0xaa>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x80,%edx
call   1050 <StringCpy@plt>
mov    -0x30(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    -0x34(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x80,%edx
call   1060 <StringCat@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f1 <AlgMorphMap+0xb1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AlgMorphMap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %esi,%ebx
mov    %rdi,%r13
mov    %rdx,%rdi
call   1030 <strlen@plt>
sub    %eax,%ebx
movslq %ebx,%rbx
mov    0x0(%r13,%rbx,1),%al
xor    %r12d,%r12d
cmp    0x0(%rbp),%al
jne    11af <AlgMorphMap+0x6f>
lea    (%rbx,%r13,1),%rdi
mov    %rbp,%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11af <AlgMorphMap+0x6f>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x80,%edx
call   1050 <StringCpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x80,%edx
call   1060 <StringCat@plt>
mov    $0x1,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @AlgMorphMap(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%13 = load i8*, i8** %9
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %12
%15 = load i8*, i8** %7
%16 = load i32, i32* %8
%17 = load i32, i32* %12
%18 = sub nsw i32 %16, %17
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %15, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = load i8*, i8** %9
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %23, %27
br i1 %28, label %29, label %52
29: ; preds = %5
%30 = load i8*, i8** %7
%31 = load i32, i32* %8
%32 = load i32, i32* %12
%33 = sub nsw i32 %31, %32
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %30, i64 %34
%36 = load i8*, i8** %9
%37 = call i64 @strcmp(i8* %35, i8* %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %52
39: ; preds = %29
%40 = load i8*, i8** %11
%41 = load i8*, i8** %7
%42 = call i32 @StringCpy(i8* %40, i8* %41, i32 128)
%43 = load i8*, i8** %11
%44 = load i32, i32* %8
%45 = load i32, i32* %12
%46 = sub nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %43, i64 %47
store i8 0, i8* %48
%49 = load i8*, i8** %11
%50 = load i8*, i8** %10
%51 = call i32 @StringCat(i8* %49, i8* %50, i32 128)
store i32 1, i32* %6
br label %53
52: ; preds = %29, %5
store i32 0, i32* %6
br label %53
53: ; preds = %52, %39
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
define i32 @AlgMorphMap(i8* %0, i32 %1, i8* %2, i8* %3, i8* %4) {
%6 = tail call i32 @strlen(i8* %2)
%7 = sub nsw i32 %1, %6
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = load i8, i8* %2
%12 = icmp eq i8 %10, %11
br i1 %12, label %13, label %20
13: ; preds = %5
%14 = tail call i64 @strcmp(i8* %9, i8* %2)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = tail call i32 @StringCpy(i8* %4, i8* %0, i32 128)
%18 = getelementptr inbounds i8, i8* %4, i64 %8
store i8 0, i8* %18
%19 = tail call i32 @StringCat(i8* %4, i8* %3, i32 128)
br label %20
20: ; preds = %5, %13, %16
%21 = phi i32 [ 1, %16 ], [ 0, %13 ], [ 0, %5 ]
ret i32 %21
}