#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 __compare_collate(char **, char **);
int strcoll(const char *s1, const char *s2) {
  if (s1 == s2)
    return 0;
  char *a = (char *)s1;
  char *b = (char *)s2;
  while (1) {
    if (*a == 0 && *b != 0)
      return -1;
    if (*a != 0 && *b == 0)
      return 1;
    int colval = __compare_collate(&a, &b);
    if (colval != 0)
      return colval;
  }
}


x86 assembly (clang, -O0):
<strcoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    113a <strcoll+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11cc <strcoll+0xbc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1176 <strcoll+0x66>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1176 <strcoll+0x66>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cc <strcoll+0xbc>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a2 <strcoll+0x92>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a2 <strcoll+0x92>
movl   $0x1,-0x4(%rbp)
jmp    11cc <strcoll+0xbc>
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <__compare_collate@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11c7 <strcoll+0xb7>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11cc <strcoll+0xbc>
jmp    114a <strcoll+0x3a>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strcoll>:
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    %rsi,%rdi
je     116a <strcoll+0x5a>
mov    %rdi,0x10(%rsp)
mov    %rsi,0x8(%rsp)
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%rbx
cmpb   $0x0,(%rdi)
mov    0x8(%rsp),%rax
movzbl (%rax),%eax
je     1150 <strcoll+0x40>
test   %al,%al
jne    1154 <strcoll+0x44>
jmp    116e <strcoll+0x5e>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %al,%al
jne    1175 <strcoll+0x65>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <__compare_collate@plt>
test   %eax,%eax
jne    117a <strcoll+0x6a>
mov    0x10(%rsp),%rdi
jmp    1130 <strcoll+0x20>
xor    %eax,%eax
jmp    117a <strcoll+0x6a>
mov    $0x1,%eax
jmp    117a <strcoll+0x6a>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @strcoll(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = load i8*, i8** %5
%11 = icmp eq i8* %9, %10
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %45
13: ; preds = %2
%14 = load i8*, i8** %4
store i8* %14, i8** %6
%15 = load i8*, i8** %5
store i8* %15, i8** %7
br label %16
16: ; preds = %13, %44
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i8*, i8** %7
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 -1, i32* %3
br label %45
27: ; preds = %21, %16
%28 = load i8*, i8** %6
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 1, i32* %3
br label %45
38: ; preds = %32, %27
%39 = call i32 @__compare_collate(i8** %6, i8** %7)
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = load i32, i32* %8
store i32 %43, i32* %3
br label %45
44: ; preds = %38
br label %16
45: ; preds = %42, %37, %26, %12
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
define i32 @strcoll(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = icmp eq i8* %0, %1
br i1 %5, label %25, label %6
6: ; preds = %2
%7 = bitcast i8** %3 to i8*
store i8* %0, i8** %3
%8 = bitcast i8** %4 to i8*
store i8* %1, i8** %4
br label %9
9: ; preds = %21, %6
%10 = phi i8* [ %22, %21 ], [ %0, %6 ]
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %12, label %16, label %17
16: ; preds = %9
br i1 %15, label %18, label %23
17: ; preds = %9
br i1 %15, label %23, label %18
18: ; preds = %16, %17
%19 = call i32 @__compare_collate(i8** %3, i8** %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i8*, i8** %3
br label %9
23: ; preds = %17, %16, %18
%24 = phi i32 [ %19, %18 ], [ -1, %16 ], [ 1, %17 ]
br label %25
25: ; preds = %2, %23
%26 = phi i32 [ %24, %23 ], [ 0, %2 ]
ret i32 %26
}