#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int length(char const *);
int /*<<< orphan*/ stderr;
int endsWithString(const char *a, const char *b) {
  if (a == NULL || b == NULL) {
    fprintf(stderr, "NULL Pointer Exception at endsWithString\n");
    exit(-1);
  }
  int i = length(a) - 1;
  int lb = length(b) - 1;
  int counter = 0;
  for (; i >= 0; i--) {
    if (a[i] != b[lb - counter]) {
      return 0;
    }
    counter++;
  }
  return 1;
}


x86 assembly (clang, -O0):
<endsWithString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1156 <endsWithString+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1175 <endsWithString+0x45>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1030 <length@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <length@plt>
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     11ec <endsWithString+0xbc>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%edx
sub    -0x24(%rbp),%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11d5 <endsWithString+0xa5>
movl   $0x0,-0x4(%rbp)
jmp    11f3 <endsWithString+0xc3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    119a <endsWithString+0x6a>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<endsWithString>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     1192 <endsWithString+0x62>
mov    %rsi,%r14
test   %rsi,%rsi
je     1192 <endsWithString+0x62>
mov    %rdi,%rbp
call   1030 <length@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <length@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ebx,%ebx
jle    118d <endsWithString+0x5d>
mov    %ebx,%edx
add    $0xffffffff,%ecx
add    $0xffffffffffffffff,%rdx
nopw   0x0(%rax,%rax,1)
mov    %edx,%esi
movzbl 0x0(%rbp,%rsi,1),%ebx
movslq %ecx,%rsi
cmp    (%r14,%rsi,1),%bl
jne    118b <endsWithString+0x5b>
add    $0xffffffff,%ecx
add    $0xffffffffffffffff,%rdx
jb     1170 <endsWithString+0x40>
jmp    118d <endsWithString+0x5d>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"NULL Pointer Exception at endsWithString\0A\00"
define i32 @endsWithString(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %11, %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = call i32 @length(i8* %19)
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %6
%22 = load i8*, i8** %5
%23 = call i32 @length(i8* %22)
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %7
store i32 0, i32* %8
br label %25
25: ; preds = %48, %18
%26 = load i32, i32* %6
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %51
28: ; preds = %25
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = load i8*, i8** %5
%36 = load i32, i32* %7
%37 = load i32, i32* %8
%38 = sub nsw i32 %36, %37
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %35, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %34, %42
br i1 %43, label %44, label %45
44: ; preds = %28
store i32 0, i32* %3
br label %52
45: ; preds = %28
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %48
48: ; preds = %45
%49 = load i32, i32* %6
%50 = add nsw i32 %49, -1
store i32 %50, i32* %6
br label %25
51: ; preds = %25
store i32 1, i32* %3
br label %52
52: ; preds = %51, %44
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"NULL Pointer Exception at endsWithString\0A\00"
define i32 @endsWithString(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i8* %1, null
%5 = or i1 %3, %4
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = tail call i32 @length(i8* %0)
%12 = tail call i32 @length(i8* %1)
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %33
14: ; preds = %10
%15 = zext i32 %11 to i64
br label %19
16: ; preds = %19
%17 = add nuw nsw i64 %20, 1
%18 = icmp eq i64 %17, %15
br i1 %18, label %33, label %19
19: ; preds = %14, %16
%20 = phi i64 [ 0, %14 ], [ %17, %16 ]
%21 = phi i64 [ %15, %14 ], [ %22, %16 ]
%22 = add nsw i64 %21, -1
%23 = and i64 %22, 4294967295
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = load i8, i8* %24
%26 = trunc i64 %20 to i32
%27 = xor i32 %26, -1
%28 = add i32 %12, %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %1, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %25, %31
br i1 %32, label %16, label %33
33: ; preds = %19, %16, %10
%34 = phi i32 [ 1, %10 ], [ 1, %16 ], [ 0, %19 ]
ret i32 %34
}