#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*/ printf(char *, ...);
int strcompare(char *p1, char *p2) {
  int com;
  while (*p1 && *p2) {
    if (*p1 == *p2) {
      p1++, p2++;
    } else {
      com = *p1 - *p2;
      break;
    }
  }
  if (*p1 == *p2) {
    com = 0;
  } else {
    com = *p1 - *p2;
  }
  if (com == 0) {
    printf("The str1 equal to str2\n");
  } else if (com < 0) {
    printf("The str1 is less than str2:%d\n", com);
  } else {
    printf("The str1 is greater than str2:%d\n", com);
  }
}


x86 assembly (clang, -O0):
<strcompare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     1145 <strcompare+0x35>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1155 <strcompare+0x45>
jmp    11a5 <strcompare+0x95>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1188 <strcompare+0x78>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11a0 <strcompare+0x90>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a5 <strcompare+0x95>
jmp    1120 <strcompare+0x10>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11c7 <strcompare+0xb7>
movl   $0x0,-0x1c(%rbp)
jmp    11da <strcompare+0xca>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
movsbl (%rcx),%ecx
sub    %ecx,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11f7 <strcompare+0xe7>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122d <strcompare+0x11d>
cmpl   $0x0,-0x1c(%rbp)
jge    1217 <strcompare+0x107>
mov    -0x1c(%rbp),%esi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1228 <strcompare+0x118>
mov    -0x1c(%rbp),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122d <strcompare+0x11d>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcompare>:
push   %rax
mov    (%rdi),%al
test   %al,%al
je     114a <strcompare+0x2a>
add    $0x1,%rdi
nopl   0x0(%rax,%rax,1)
movzbl (%rsi),%ecx
test   %cl,%cl
je     114c <strcompare+0x2c>
cmp    %cl,%al
jne    114c <strcompare+0x2c>
add    $0x1,%rsi
movzbl (%rdi),%eax
add    $0x1,%rdi
test   %al,%al
jne    1130 <strcompare+0x10>
xor    %eax,%eax
movsbl (%rsi),%ecx
cmp    %cl,%al
je     1167 <strcompare+0x47>
movsbl %al,%esi
sub    %ecx,%esi
test   %esi,%esi
je     1167 <strcompare+0x47>
js     1175 <strcompare+0x55>
lea    0xeba(%rip),%rdi
jmp    117c <strcompare+0x5c>
lea    0xed3(%rip),%rdi
call   1030 <puts@plt>
pop    %rcx
ret
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
pop    %rcx
ret

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

LLVM IR (-O2):
@.str.1 = [31 x i8] c"The str1 is less than str2:%d\0A\00"
@.str.2 = [34 x i8] c"The str1 is greater than str2:%d\0A\00"
@str = [23 x i8] c"The str1 equal to str2\00"
define i32 @strcompare(i8* nocapture %0, i8* nocapture %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %2, %13
%6 = phi i8 [ %16, %13 ], [ %3, %2 ]
%7 = phi i8* [ %15, %13 ], [ %1, %2 ]
%8 = phi i8* [ %14, %13 ], [ %0, %2 ]
%9 = load i8, i8* %7
%10 = icmp ne i8 %9, 0
%11 = icmp eq i8 %6, %9
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %18
13: ; preds = %5
%14 = getelementptr inbounds i8, i8* %8, i64 1
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = load i8, i8* %14
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %5
18: ; preds = %5, %13, %2
%19 = phi i8* [ %1, %2 ], [ %15, %13 ], [ %7, %5 ]
%20 = phi i8 [ 0, %2 ], [ 0, %13 ], [ %6, %5 ]
%21 = load i8, i8* %19
%22 = icmp eq i8 %20, %21
%23 = sext i8 %21 to i32
%24 = sext i8 %20 to i32
%25 = sub nsw i32 %24, %23
%26 = icmp eq i32 %25, 0
%27 = select i1 %22, i1 true, i1 %26
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %36
30: ; preds = %18
%31 = icmp slt i32 %25, 0
br i1 %31, label %32, label %34
32: ; preds = %30
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %36
34: ; preds = %30
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %36
36: ; preds = %32, %34, %28
ret i32 undef
}