#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 int /*<<< orphan*/ wchar_t;

/* Variables and functions */
int MB_CUR_MAX;
int /*<<< orphan*/ err(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int strcoll(char const *, char const *);
int /*<<< orphan*/ *towcs(char const *);
int wcscoll(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int mdiroll(const char *s1, const char *s2) {
  wchar_t *w1, *w2;
  int ret;
  if (MB_CUR_MAX == 1)
    return (strcoll(s1, s2));
  if ((w1 = towcs(s1)) == NULL || (w2 = towcs(s2)) == NULL)
    err(1, NULL);
  ret = wcscoll(w1, w2);
  free(w1);
  free(w2);
  return (ret);
}


x86 assembly (clang, -O0):
<mdiroll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e91(%rip),%rax
cmpl   $0x1,(%rax)
jne    1185 <mdiroll+0x35>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcoll@plt>
mov    %eax,-0x4(%rbp)
jmp    11e9 <mdiroll+0x99>
mov    -0x10(%rbp),%rdi
call   1050 <towcs@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11b3 <mdiroll+0x63>
mov    -0x18(%rbp),%rdi
call   1050 <towcs@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11c1 <mdiroll+0x71>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <err@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <wcscoll@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mdiroll>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    0x2e9a(%rip),%rax
cmpl   $0x1,(%rax)
jne    116f <mdiroll+0x1f>
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <strcoll@plt>
call   1050 <towcs@plt>
mov    %rax,%r14
test   %rax,%rax
je     118c <mdiroll+0x3c>
mov    %rbx,%rdi
call   1050 <towcs@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    119a <mdiroll+0x4a>
xor    %ebx,%ebx
mov    $0x1,%edi
xor    %esi,%esi
call   1060 <err@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <wcscoll@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@MB_CUR_MAX = global i32 0
define i32 @mdiroll(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 i32, i32* @MB_CUR_MAX
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8*, i8** %5
%14 = call i32 @strcoll(i8* %12, i8* %13)
store i32 %14, i32* %3
br label %34
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i32* @towcs(i8* %16)
store i32* %17, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i32* @towcs(i8* %20)
store i32* %21, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %19, %15
%24 = call i32 @err(i32 1, i32* null)
br label %25
25: ; preds = %23, %19
%26 = load i32*, i32** %6
%27 = load i32*, i32** %7
%28 = call i32 @wcscoll(i32* %26, i32* %27)
store i32 %28, i32* %8
%29 = load i32*, i32** %6
%30 = call i32 @free(i32* %29)
%31 = load i32*, i32** %7
%32 = call i32 @free(i32* %31)
%33 = load i32, i32* %8
store i32 %33, i32* %3
br label %34
34: ; preds = %25, %11
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@MB_CUR_MAX = global i32 0
define i32 @mdiroll(i8* %0, i8* %1) {
%3 = load i32, i32* @MB_CUR_MAX
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @strcoll(i8* %0, i8* %1)
br label %20
7: ; preds = %2
%8 = tail call i32* @towcs(i8* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32* @towcs(i8* %1)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10, %7
%14 = tail call i32 @err(i32 1, i32* null)
br label %15
15: ; preds = %13, %10
%16 = phi i32* [ null, %13 ], [ %11, %10 ]
%17 = tail call i32 @wcscoll(i32* %8, i32* %16)
%18 = tail call i32 @free(i32* %8)
%19 = tail call i32 @free(i32* %16)
br label %20
20: ; preds = %15, %5
%21 = phi i32 [ %6, %5 ], [ %17, %15 ]
ret i32 %21
}