#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*/ strcmp(char const *, char const *);
int compare_strings(int op, const char *x, const char *y) {
  switch (op) {
  case 1:
    return !strcmp(x, y) ? 1 : 0;
  case 2:
    return strcmp(x, y) > 0 ? 1 : 0;
  case 3:
    return strcmp(x, y) < 0 ? 1 : 0;
  case 4:
    return strcmp(x, y) >= 0 ? 1 : 0;
  case 5:
    return strcmp(x, y) <= 0 ? 1 : 0;
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<compare_strings>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x4,%eax
ja     1207 <compare_strings+0xf7>
mov    -0x20(%rbp),%rax
lea    0xebd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
setne  %dl
xor    $0xff,%dl
xor    %eax,%eax
mov    $0x1,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    120e <compare_strings+0xfe>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovg  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    120e <compare_strings+0xfe>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovl  %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    120e <compare_strings+0xfe>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovge %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    120e <compare_strings+0xfe>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcmp@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovle %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    120e <compare_strings+0xfe>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compare_strings>:
push   %rax
add    $0xffffffff,%edi
cmp    $0x4,%edi
ja     113f <compare_strings+0x2f>
lea    0xee0(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1030 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
sete   %al
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1030 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setg   %al
pop    %rcx
ret
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1030 <strcmp@plt>
jmp    1173 <compare_strings+0x63>
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1030 <strcmp@plt>
not    %eax
shr    $0x1f,%eax
pop    %rcx
ret
mov    %rsi,%rdi
mov    %rdx,%rsi
call   1030 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setle  %al
pop    %rcx
ret

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

LLVM IR (-O2):
define i32 @compare_strings(i32 %0, i8* nocapture %1, i8* nocapture %2) {
switch i32 %0, label %23 [
i32 1, label %4
i32 2, label %8
i32 3, label %12
i32 4, label %15
i32 5, label %19
]
4: ; preds = %3
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(1) %2)
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
br label %23
8: ; preds = %3
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(1) %2)
%10 = icmp sgt i32 %9, 0
%11 = zext i1 %10 to i32
br label %23
12: ; preds = %3
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(1) %2)
%14 = lshr i32 %13, 31
br label %23
15: ; preds = %3
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(1) %2)
%17 = xor i32 %16, -1
%18 = lshr i32 %17, 31
br label %23
19: ; preds = %3
%20 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(1) %2)
%21 = icmp slt i32 %20, 1
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %3, %19, %15, %12, %8, %4
%24 = phi i32 [ %22, %19 ], [ %18, %15 ], [ %14, %12 ], [ %11, %8 ], [ %7, %4 ], [ 0, %3 ]
ret i32 %24
}