#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*/ cha_tmp_atom(char *);
int err_msg(char *, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int stem(char *string, char *ending) {
  int string_len, ending_len;
  if (!string[0])
    return 0;
  string_len = strlen(string);
  ending_len = strlen(ending);
  if (string_len < ending_len ||
      strcmp(string + string_len - ending_len, ending))
    return err_msg(":ending conflicts headword", cha_tmp_atom(ending));
  string[string_len - ending_len] = '\0';
  return string_len - ending_len;
}


x86 assembly (clang, -O0):
<stem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1169 <stem+0x29>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <stem+0xb0>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jl     11b7 <stem+0x77>
mov    -0x10(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
movslq -0x20(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11d6 <stem+0x96>
mov    -0x18(%rbp),%rdi
call   1030 <cha_tmp_atom@plt>
mov    %eax,%esi
lea    0xe37(%rip),%rdi
call   1060 <err_msg@plt>
mov    %eax,-0x4(%rbp)
jmp    11f0 <stem+0xb0>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stem>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     11a1 <stem+0x61>
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r15d,%ebp
sub    %eax,%ebp
jl     1181 <stem+0x41>
movslq %r15d,%rdi
add    %rbx,%rdi
cltq
sub    %rax,%rdi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11a5 <stem+0x65>
mov    %r14,%rdi
call   1030 <cha_tmp_atom@plt>
lea    0xe70(%rip),%rdi
mov    %eax,%esi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <err_msg@plt>
xor    %ebp,%ebp
jmp    11ac <stem+0x6c>
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c":ending conflicts headword\00"
define i32 @stem(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %47
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %6
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = icmp slt i32 %18, %19
br i1 %20, label %33, label %21
21: ; preds = %13
%22 = load i8*, i8** %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = sub i64 0, %27
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = load i8*, i8** %5
%31 = call i64 @strcmp(i8* %29, i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %21, %13
%34 = load i8*, i8** %5
%35 = call i32 @cha_tmp_atom(i8* %34)
%36 = call i32 @err_msg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %35)
store i32 %36, i32* %3
br label %47
37: ; preds = %21
%38 = load i8*, i8** %4
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = sub nsw i32 %39, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %38, i64 %42
store i8 0, i8* %43
%44 = load i32, i32* %6
%45 = load i32, i32* %7
%46 = sub nsw i32 %44, %45
store i32 %46, i32* %3
br label %47
47: ; preds = %37, %33, %12
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [27 x i8] c":ending conflicts headword\00"
define i32 @stem(i8* %0, i8* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %24, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i32 @strlen(i8* %1)
%8 = icmp slt i32 %6, %7
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = sext i32 %6 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = sext i32 %7 to i64
%13 = sub nsw i64 0, %12
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = tail call i64 @strcmp(i8* %14, i8* %1)
%16 = icmp eq i64 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %9, %5
%18 = tail call i32 @cha_tmp_atom(i8* %1)
%19 = tail call i32 @err_msg(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %24
20: ; preds = %9
%21 = sub nsw i32 %6, %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 0, i8* %23
br label %24
24: ; preds = %2, %20, %17
%25 = phi i32 [ %19, %17 ], [ %21, %20 ], [ 0, %2 ]
ret i32 %25
}