#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*/ fprintf(int /*<<< orphan*/, char *, unsigned int,
                           unsigned int, unsigned int);
int /*<<< orphan*/ stderr;
int _loopDetect(unsigned int *oldrel, unsigned int rel, unsigned int *oldabs,
                unsigned int absol) {
  if (*oldrel && rel > *oldrel && absol == *oldabs) {
    fprintf(stderr, "loop detected! oldrel=%d newrel=%d abs=%d\n", *oldrel, rel,
            absol);
    return -1;
  }
  if (rel >= 2 * *oldrel + 1) {
    *oldrel = rel;
    *oldabs = absol;
  }
  return 0;
}


x86 assembly (clang, -O0):
<_loopDetect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
je     117f <_loopDetect+0x6f>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jbe    117f <_loopDetect+0x6f>
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jne    117f <_loopDetect+0x6f>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x14(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xe92(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11af <_loopDetect+0x9f>
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jb     11a8 <_loopDetect+0x98>
mov    -0x14(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_loopDetect>:
push   %rax
mov    %ecx,%r8d
mov    %esi,%ecx
mov    (%rdi),%eax
test   %eax,%eax
je     1143 <_loopDetect+0x33>
cmp    %ecx,%eax
jae    1143 <_loopDetect+0x33>
cmp    %r8d,(%rdx)
jne    1143 <_loopDetect+0x33>
mov    0x2eb4(%rip),%rdx
mov    (%rdx),%edi
lea    0xecb(%rip),%rsi
mov    %eax,%edx
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
lea    (%rax,%rax,1),%esi
add    $0x1,%esi
xor    %eax,%eax
cmp    %ecx,%esi
ja     1154 <_loopDetect+0x44>
mov    %ecx,(%rdi)
mov    %r8d,(%rdx)
pop    %rcx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"loop detected! oldrel=%d newrel=%d abs=%d\0A\00"
define i32 @_loopDetect(i32* %0, i32 %1, i32* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32* %2, i32** %8
store i32 %3, i32* %9
%10 = load i32*, i32** %6
%11 = load i32, i32* %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %30
13: ; preds = %4
%14 = load i32, i32* %7
%15 = load i32*, i32** %6
%16 = load i32, i32* %15
%17 = icmp ugt i32 %14, %16
br i1 %17, label %18, label %30
18: ; preds = %13
%19 = load i32, i32* %9
%20 = load i32*, i32** %8
%21 = load i32, i32* %20
%22 = icmp eq i32 %19, %21
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = load i32*, i32** %6
%26 = load i32, i32* %25
%27 = load i32, i32* %7
%28 = load i32, i32* %9
%29 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %27, i32 %28)
store i32 -1, i32* %5
br label %43
30: ; preds = %18, %13, %4
%31 = load i32, i32* %7
%32 = load i32*, i32** %6
%33 = load i32, i32* %32
%34 = mul i32 2, %33
%35 = add i32 %34, 1
%36 = icmp uge i32 %31, %35
br i1 %36, label %37, label %42
37: ; preds = %30
%38 = load i32, i32* %7
%39 = load i32*, i32** %6
store i32 %38, i32* %39
%40 = load i32, i32* %9
%41 = load i32*, i32** %8
store i32 %40, i32* %41
br label %42
42: ; preds = %37, %30
store i32 0, i32* %5
br label %43
43: ; preds = %42, %23
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"loop detected! oldrel=%d newrel=%d abs=%d\0A\00"
define i32 @_loopDetect(i32* nocapture %0, i32 %1, i32* nocapture %2, i32 %3) {
%5 = load i32, i32* %0
%6 = icmp ne i32 %5, 0
%7 = icmp ult i32 %5, %1
%8 = and i1 %6, %7
br i1 %8, label %9, label %15
9: ; preds = %4
%10 = load i32, i32* %2
%11 = icmp eq i32 %10, %3
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %1, i32 %3)
br label %20
15: ; preds = %9, %4
%16 = shl i32 %5, 1
%17 = or i32 %16, 1
%18 = icmp ugt i32 %17, %1
br i1 %18, label %20, label %19
19: ; preds = %15
store i32 %1, i32* %0
store i32 %3, i32* %2
br label %20
20: ; preds = %15, %19, %12
%21 = phi i32 [ -1, %12 ], [ 0, %19 ], [ 0, %15 ]
ret i32 %21
}