#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*/ sprintf(char *, char *, int, int);
int cmpfun(const void *a, const void *b) {
  static char buf1[32], buf2[32];
  int i;
  sprintf(buf1, "%d%d", *(int *)a, *(int *)b);
  sprintf(buf2, "%d%d", *(int *)b, *(int *)a);
  for (i = 0; buf1[i] && buf2[i]; i++) {
    if (buf1[i] > buf2[i])
      return (-1);
    else if (buf1[i] < buf2[i])
      return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<cmpfun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    0x2f0d(%rip),%rdi
lea    0xec6(%rip),%rsi
call   1030 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0x2f0e(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1030 <sprintf@plt>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rcx
lea    0x2ed0(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
je     119a <cmpfun+0x8a>
movslq -0x1c(%rbp),%rcx
lea    0x2ed3(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11aa <cmpfun+0x9a>
jmp    1226 <cmpfun+0x116>
movslq -0x1c(%rbp),%rcx
lea    0x2e8b(%rip),%rax
movsbl (%rax,%rcx,1),%eax
movslq -0x1c(%rbp),%rdx
lea    0x2e9c(%rip),%rcx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jle    11dc <cmpfun+0xcc>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <cmpfun+0x11d>
movslq -0x1c(%rbp),%rcx
lea    0x2e59(%rip),%rax
movsbl (%rax,%rcx,1),%eax
movslq -0x1c(%rbp),%rdx
lea    0x2e6a(%rip),%rcx
movsbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jge    120e <cmpfun+0xfe>
movl   $0x1,-0x4(%rbp)
jmp    122d <cmpfun+0x11d>
jmp    1213 <cmpfun+0x103>
jmp    1218 <cmpfun+0x108>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1165 <cmpfun+0x55>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmpfun>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r15
mov    (%rdi),%edx
mov    (%rsi),%ecx
lea    0x2f17(%rip),%r14
lea    0xed0(%rip),%r12
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <sprintf@plt>
mov    (%rbx),%edx
mov    (%r15),%ecx
lea    0x2f19(%rip),%r15
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <sprintf@plt>
mov    0x2ee8(%rip),%cl
xor    %eax,%eax
test   %cl,%cl
je     118b <cmpfun+0x7b>
xor    %edx,%edx
movzbl (%rdx,%r15,1),%ebx
test   %bl,%bl
je     118b <cmpfun+0x7b>
cmp    %bl,%cl
jg     117f <cmpfun+0x6f>
jl     1186 <cmpfun+0x76>
movzbl 0x1(%rdx,%r14,1),%ecx
add    $0x1,%rdx
test   %cl,%cl
jne    1160 <cmpfun+0x50>
jmp    118b <cmpfun+0x7b>
mov    $0xffffffff,%eax
jmp    118b <cmpfun+0x7b>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@cmpfun.buf1 = internal global [32 x i8] zeroinitializer
@cmpfun.buf2 = internal global [32 x i8] zeroinitializer
@.str = [5 x i8] c"%d%d\00"
define i32 @cmpfun(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %4
%8 = bitcast i8* %7 to i32*
%9 = load i32, i32* %8
%10 = load i8*, i8** %5
%11 = bitcast i8* %10 to i32*
%12 = load i32, i32* %11
%13 = call i32 @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @cmpfun.buf1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %12)
%14 = load i8*, i8** %5
%15 = bitcast i8* %14 to i32*
%16 = load i32, i32* %15
%17 = load i8*, i8** %4
%18 = bitcast i8* %17 to i32*
%19 = load i32, i32* %18
%20 = call i32 @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @cmpfun.buf2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %19)
store i32 0, i32* %6
br label %21
21: ; preds = %65, %2
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [32 x i8], [32 x i8]* @cmpfun.buf1, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %21
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [32 x i8], [32 x i8]* @cmpfun.buf2, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br label %35
35: ; preds = %28, %21
%36 = phi i1 [ false, %21 ], [ %34, %28 ]
br i1 %36, label %37, label %68
37: ; preds = %35
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [32 x i8], [32 x i8]* @cmpfun.buf1, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [32 x i8], [32 x i8]* @cmpfun.buf2, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp sgt i32 %42, %47
br i1 %48, label %49, label %50
49: ; preds = %37
store i32 -1, i32* %3
br label %69
50: ; preds = %37
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [32 x i8], [32 x i8]* @cmpfun.buf1, i64 0, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [32 x i8], [32 x i8]* @cmpfun.buf2, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp slt i32 %55, %60
br i1 %61, label %62, label %63
62: ; preds = %50
store i32 1, i32* %3
br label %69
63: ; preds = %50
br label %64
64: ; preds = %63
br label %65
65: ; preds = %64
%66 = load i32, i32* %6
%67 = add nsw i32 %66, 1
store i32 %67, i32* %6
br label %21
68: ; preds = %35
store i32 0, i32* %3
br label %69
69: ; preds = %68, %62, %49
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
@cmpfun.buf1 = internal global [32 x i8] zeroinitializer
@cmpfun.buf2 = internal global [32 x i8] zeroinitializer
@.str = [5 x i8] c"%d%d\00"
define i32 @cmpfun(i8* nocapture %0, i8* nocapture %1) {
%3 = bitcast i8* %0 to i32*
%4 = load i32, i32* %3
%5 = bitcast i8* %1 to i32*
%6 = load i32, i32* %5
%7 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @cmpfun.buf1, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %6)
%8 = load i32, i32* %5
%9 = load i32, i32* %3
%10 = tail call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @cmpfun.buf2, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %9)
%11 = load i8, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @cmpfun.buf1, i64 0, i64 0)
%12 = icmp eq i8 %11, 0
br i1 %12, label %28, label %17
13: ; preds = %25
%14 = getelementptr inbounds [32 x i8], [32 x i8]* @cmpfun.buf1, i64 0, i64 %27
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %28, label %17
17: ; preds = %2, %13
%18 = phi i64 [ %27, %13 ], [ 0, %2 ]
%19 = phi i8 [ %15, %13 ], [ %11, %2 ]
%20 = getelementptr inbounds [32 x i8], [32 x i8]* @cmpfun.buf2, i64 0, i64 %18
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %17
%24 = icmp sgt i8 %19, %21
br i1 %24, label %28, label %25
25: ; preds = %23
%26 = icmp slt i8 %19, %21
%27 = add nuw i64 %18, 1
br i1 %26, label %28, label %13
28: ; preds = %23, %25, %13, %17, %2
%29 = phi i32 [ 0, %2 ], [ 0, %17 ], [ 0, %13 ], [ 1, %25 ], [ -1, %23 ]
ret i32 %29
}