#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, int);
int comparefunc(const void *arg1, const void *arg2) {
  const int *ptr1 = (const int *)arg1;
  const int *ptr2 = (const int *)arg2;
  int val1 = *ptr1;
  int val2 = *ptr2;
  printf("comparefunc: %d %d\n", val1, val2);
  if (val1 < val2) {
    return -1;
  }
  if (val1 == val2) {
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<comparefunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    116c <comparefunc+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <comparefunc+0x7b>
mov    -0x2c(%rbp),%eax
cmp    -0x30(%rbp),%eax
jne    1184 <comparefunc+0x74>
movl   $0x0,-0x4(%rbp)
jmp    118b <comparefunc+0x7b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<comparefunc>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%ebx
mov    (%rsi),%ebp
lea    0xee2(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <printf@plt>
xor    %ecx,%ecx
cmp    %ebp,%ebx
setne  %cl
mov    $0xffffffff,%eax
cmovge %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"comparefunc: %d %d\0A\00"
define i32 @comparefunc(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = bitcast i8* %10 to i32*
store i32* %11, i32** %6
%12 = load i8*, i8** %5
%13 = bitcast i8* %12 to i32*
store i32* %13, i32** %7
%14 = load i32*, i32** %6
%15 = load i32, i32* %14
store i32 %15, i32* %8
%16 = load i32*, i32** %7
%17 = load i32, i32* %16
store i32 %17, i32* %9
%18 = load i32, i32* %8
%19 = load i32, i32* %9
%20 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %2
store i32 -1, i32* %3
br label %31
25: ; preds = %2
%26 = load i32, i32* %8
%27 = load i32, i32* %9
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %25
store i32 0, i32* %3
br label %31
30: ; preds = %25
store i32 1, i32* %3
br label %31
31: ; preds = %30, %29, %24
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@.str = [20 x i8] c"comparefunc: %d %d\0A\00"
define i32 @comparefunc(i8* nocapture %0, i8* nocapture %1) {
%3 = bitcast i8* %0 to i32*
%4 = bitcast i8* %1 to i32*
%5 = load i32, i32* %3
%6 = load i32, i32* %4
%7 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = icmp slt i32 %5, %6
%9 = icmp ne i32 %5, %6
%10 = zext i1 %9 to i32
%11 = select i1 %8, i32 -1, i32 %10
ret i32 %11
}