#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 strcmp1(char *, char *);
int strlen1(char *);
int diffByOne(char *str1, char *str2) {
  int i, diffcount = 0;
  if (1 != strcmp1(str1, str2))
    return 0;
  for (i = 0; i < strlen1(str1); ++i) {
    if (str1[i] != str2[i]) {
      diffcount++;
      if (diffcount > 1)
        return 0;
    }
  }
  if (diffcount == 1)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<diffByOne>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcmp1@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     115f <diffByOne+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <diffByOne+0xd6>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen1@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jge    11d9 <diffByOne+0xb9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    -0x18(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
je     11c6 <diffByOne+0xa6>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jle    11c1 <diffByOne+0xa1>
movl   $0x0,-0x4(%rbp)
jmp    11f6 <diffByOne+0xd6>
jmp    11c6 <diffByOne+0xa6>
jmp    11cb <diffByOne+0xab>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <diffByOne+0x46>
cmpl   $0x1,-0x20(%rbp)
jne    11ef <diffByOne+0xcf>
movl   $0x1,-0x4(%rbp)
jmp    11f6 <diffByOne+0xd6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diffByOne>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strcmp1@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
jne    1185 <diffByOne+0x65>
mov    %r15,%rdi
call   1030 <strlen1@plt>
test   %eax,%eax
jle    117b <diffByOne+0x5b>
xor    %ebx,%ebx
xor    %ebp,%ebp
jmp    1163 <diffByOne+0x43>
nopl   (%rax)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen1@plt>
cltq
cmp    %rax,%rbx
jge    117d <diffByOne+0x5d>
movzbl (%r15,%rbx,1),%eax
cmp    (%r14,%rbx,1),%al
je     1150 <diffByOne+0x30>
test   %ebp,%ebp
mov    $0x1,%ebp
jle    1150 <diffByOne+0x30>
xor    %eax,%eax
jmp    1185 <diffByOne+0x65>
xor    %ebp,%ebp
xor    %eax,%eax
cmp    $0x1,%ebp
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @diffByOne(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
store i32 0, i32* %7
%8 = load i8*, i8** %4
%9 = load i8*, i8** %5
%10 = call i32 @strcmp1(i8* %8, i8* %9)
%11 = icmp ne i32 1, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %49
13: ; preds = %2
store i32 0, i32* %6
br label %14
14: ; preds = %41, %13
%15 = load i32, i32* %6
%16 = load i8*, i8** %4
%17 = call i32 @strlen1(i8* %16)
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %44
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = load i8*, i8** %5
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %25, %31
br i1 %32, label %33, label %40
33: ; preds = %19
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp sgt i32 %36, 1
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 0, i32* %3
br label %49
39: ; preds = %33
br label %40
40: ; preds = %39, %19
br label %41
41: ; preds = %40
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %14
44: ; preds = %14
%45 = load i32, i32* %7
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %48
47: ; preds = %44
store i32 1, i32* %3
br label %49
48: ; preds = %44
store i32 0, i32* %3
br label %49
49: ; preds = %48, %47, %38, %12
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
define i32 @diffByOne(i8* %0, i8* %1) {
%3 = tail call i32 @strcmp1(i8* %0, i8* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %28
5: ; preds = %2
%6 = tail call i32 @strlen1(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %5, %18
%9 = phi i64 [ %20, %18 ], [ 0, %5 ]
%10 = phi i32 [ %19, %18 ], [ 0, %5 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = load i8, i8* %11
%13 = getelementptr inbounds i8, i8* %1, i64 %9
%14 = load i8, i8* %13
%15 = icmp eq i8 %12, %14
br i1 %15, label %18, label %16
16: ; preds = %8
%17 = icmp sgt i32 %10, 0
br i1 %17, label %28, label %18
18: ; preds = %8, %16
%19 = phi i32 [ 1, %16 ], [ %10, %8 ]
%20 = add nuw nsw i64 %9, 1
%21 = tail call i32 @strlen1(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %8, label %24
24: ; preds = %18, %5
%25 = phi i32 [ 0, %5 ], [ %19, %18 ]
%26 = icmp eq i32 %25, 1
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %16, %24, %2
%29 = phi i32 [ 0, %2 ], [ %27, %24 ], [ 0, %16 ]
ret i32 %29
}