#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 */
typedef scalar_t__ uint8_t;

/* Variables and functions */
int strcmp(const char *s1, const char *s2) {
  do {
    if (*s1++ != *s2++)
      return (uint8_t)s1[-1] > (uint8_t)s2[-1] ? 1 : -1;
  } while (s1[-1] != '\0');
  return 0;
}


x86 assembly (clang, -O0):
<strcmp>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1162 <strcmp+0x62>
mov    -0x10(%rbp),%rax
movsbq -0x1(%rax),%rdx
mov    -0x18(%rbp),%rax
movsbq -0x1(%rax),%rsi
mov    $0xffffffff,%eax
mov    $0x1,%ecx
cmp    %rsi,%rdx
cmovg  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    117f <strcmp+0x7f>
jmp    1167 <strcmp+0x67>
mov    -0x10(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x0,%eax
jne    110c <strcmp+0xc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcmp>:
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rdi,%rax,1),%ecx
cmp    (%rsi,%rax,1),%cl
jne    1124 <strcmp+0x24>
add    $0x1,%rax
test   %cl,%cl
jne    1110 <strcmp+0x10>
xor    %eax,%eax
ret
setg   %al
movzbl %al,%eax
add    %eax,%eax
add    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @strcmp(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
br label %6
6: ; preds = %29, %2
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i32 1
store i8* %8, i8** %4
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %5
%13 = load i8, i8* %11
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %10, %14
br i1 %15, label %16, label %28
16: ; preds = %6
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 -1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i64
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i64 -1
%23 = load i8, i8* %22
%24 = sext i8 %23 to i64
%25 = icmp sgt i64 %20, %24
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 1, i32 -1
store i32 %27, i32* %3
br label %36
28: ; preds = %6
br label %29
29: ; preds = %28
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 -1
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %6, label %35
35: ; preds = %29
store i32 0, i32* %3
br label %36
36: ; preds = %35, %16
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @strcmp(i8* nocapture %0, i8* nocapture %1) {
br label %3
3: ; preds = %12, %2
%4 = phi i8* [ %0, %2 ], [ %14, %12 ]
%5 = phi i8* [ %1, %2 ], [ %13, %12 ]
%6 = load i8, i8* %4
%7 = load i8, i8* %5
%8 = icmp eq i8 %6, %7
br i1 %8, label %12, label %9
9: ; preds = %3
%10 = icmp sgt i8 %6, %7
%11 = select i1 %10, i32 1, i32 -1
br label %16
12: ; preds = %3
%13 = getelementptr inbounds i8, i8* %5, i64 1
%14 = getelementptr inbounds i8, i8* %4, i64 1
%15 = icmp eq i8 %6, 0
br i1 %15, label %16, label %3
16: ; preds = %12, %9
%17 = phi i32 [ %11, %9 ], [ 0, %12 ]
ret i32 %17
}