#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 */
struct rtrb_traverser {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char const *, int, int);
int *rtrb_t_cur(struct rtrb_traverser *);
int *rtrb_t_next(struct rtrb_traverser *);
int *rtrb_t_prev(struct rtrb_traverser *);
int check_traverser(struct rtrb_traverser *trav, int i, int n,
                    const char *label) {
  int okay = 1;
  int *cur, *prev, *next;
  prev = rtrb_t_prev(trav);
  if ((i == 0 && prev != NULL) || (i > 0 && (prev == NULL || *prev != i - 1))) {
    printf("   %s traverser ahead of %d, but should be ahead of %d.\n", label,
           prev != NULL ? *prev : -1, i == 0 ? -1 : i - 1);
    okay = 0;
  }
  rtrb_t_next(trav);
  cur = rtrb_t_cur(trav);
  if (cur == NULL || *cur != i) {
    printf("   %s traverser at %d, but should be at %d.\n", label,
           cur != NULL ? *cur : -1, i);
    okay = 0;
  }
  next = rtrb_t_next(trav);
  if ((i == n - 1 && next != NULL) ||
      (i != n - 1 && (next == NULL || *next != i + 1))) {
    printf("   %s traverser behind %d, but should be behind %d.\n", label,
           next != NULL ? *next : -1, i == n - 1 ? -1 : i + 1);
    okay = 0;
  }
  rtrb_t_prev(trav);
  return okay;
}


x86 assembly (clang, -O0):
<check_traverser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <rtrb_t_prev@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1182 <check_traverser+0x42>
cmpq   $0x0,-0x30(%rbp)
jne    11ab <check_traverser+0x6b>
cmpl   $0x0,-0xc(%rbp)
jle    121c <check_traverser+0xdc>
cmpq   $0x0,-0x30(%rbp)
je     11ab <check_traverser+0x6b>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     121c <check_traverser+0xdc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11cc <check_traverser+0x8c>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    11d9 <check_traverser+0x99>
mov    $0xffffffff,%eax
mov    %eax,-0x44(%rbp)
jmp    11d9 <check_traverser+0x99>
mov    -0x44(%rbp),%eax
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11f6 <check_traverser+0xb6>
mov    $0xffffffff,%eax
mov    %eax,-0x4c(%rbp)
jmp    11ff <check_traverser+0xbf>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%edx
mov    -0x40(%rbp),%rsi
mov    -0x4c(%rbp),%ecx
lea    0xdf0(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rtrb_t_next@plt>
mov    -0x8(%rbp),%rdi
call   1060 <rtrb_t_cur@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     124c <check_traverser+0x10c>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
cmp    -0xc(%rbp),%eax
je     1297 <check_traverser+0x157>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     126d <check_traverser+0x12d>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
jmp    127a <check_traverser+0x13a>
mov    $0xffffffff,%eax
mov    %eax,-0x5c(%rbp)
jmp    127a <check_traverser+0x13a>
mov    -0x58(%rbp),%rsi
mov    -0x5c(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xdae(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rtrb_t_next@plt>
mov    %rax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    12c0 <check_traverser+0x180>
cmpq   $0x0,-0x38(%rbp)
jne    12f0 <check_traverser+0x1b0>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1368 <check_traverser+0x228>
cmpq   $0x0,-0x38(%rbp)
je     12f0 <check_traverser+0x1b0>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
je     1368 <check_traverser+0x228>
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1311 <check_traverser+0x1d1>
mov    -0x38(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
jmp    131e <check_traverser+0x1de>
mov    $0xffffffff,%eax
mov    %eax,-0x6c(%rbp)
jmp    131e <check_traverser+0x1de>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1342 <check_traverser+0x202>
mov    $0xffffffff,%eax
mov    %eax,-0x74(%rbp)
jmp    134b <check_traverser+0x20b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
mov    -0x70(%rbp),%edx
mov    -0x68(%rbp),%rsi
mov    -0x74(%rbp),%ecx
lea    0xd0a(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <rtrb_t_prev@plt>
mov    -0x1c(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_traverser>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <rtrb_t_prev@plt>
test   %ebp,%ebp
jne    116a <check_traverser+0x2a>
test   %rax,%rax
je     116a <check_traverser+0x2a>
test   %rax,%rax
je     1182 <check_traverser+0x42>
mov    (%rax),%edx
jmp    1187 <check_traverser+0x47>
mov    $0x1,%r12d
test   %ebp,%ebp
jle    119c <check_traverser+0x5c>
test   %rax,%rax
je     1161 <check_traverser+0x21>
lea    -0x1(%rbp),%ecx
cmp    %ecx,(%rax)
jne    1161 <check_traverser+0x21>
jmp    119c <check_traverser+0x5c>
mov    $0xffffffff,%edx
lea    -0x1(%rbp),%ecx
lea    0xe6f(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %r12d,%r12d
mov    %rbx,%rdi
call   1030 <rtrb_t_next@plt>
mov    %rbx,%rdi
call   1060 <rtrb_t_cur@plt>
test   %rax,%rax
je     11b9 <check_traverser+0x79>
mov    (%rax),%edx
cmp    %ebp,%edx
jne    11be <check_traverser+0x7e>
jmp    11d2 <check_traverser+0x92>
mov    $0xffffffff,%edx
lea    0xe74(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%ecx
call   1040 <printf@plt>
xor    %r12d,%r12d
mov    %rbx,%rdi
call   1030 <rtrb_t_next@plt>
add    $0xffffffff,%r15d
cmp    %ebp,%r15d
jne    1216 <check_traverser+0xd6>
test   %rax,%rax
je     1216 <check_traverser+0xd6>
mov    $0xffffffff,%esi
mov    $0xffffffff,%edx
test   %rax,%rax
je     11f9 <check_traverser+0xb9>
mov    (%rax),%edx
lea    0x1(%rbp),%ecx
cmp    %ebp,%r15d
cmove  %esi,%ecx
lea    0xe5d(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %r12d,%r12d
jmp    1227 <check_traverser+0xe7>
cmp    %ebp,%r15d
je     1227 <check_traverser+0xe7>
test   %rax,%rax
je     11e8 <check_traverser+0xa8>
lea    0x1(%rbp),%ecx
cmp    %ecx,(%rax)
jne    11e8 <check_traverser+0xa8>
mov    %rbx,%rdi
call   1050 <rtrb_t_prev@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rtrb_traverser = type { i32 }
@.str = [57 x i8] c" %s traverser ahead of %d, but should be ahead of %d.\0A\00"
@.str.1 = [45 x i8] c" %s traverser at %d, but should be at %d.\0A\00"
@.str.2 = [53 x i8] c" %s traverser behind %d, but should be behind %d.\0A\00"
define i32 @check_traverser(%struct.rtrb_traverser* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca %struct.rtrb_traverser*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
store %struct.rtrb_traverser* %0, %struct.rtrb_traverser** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i32 1, i32* %9
%13 = load %struct.rtrb_traverser*, %struct.rtrb_traverser** %5
%14 = call i32* @rtrb_t_prev(%struct.rtrb_traverser* %13)
store i32* %14, i32** %11
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %4
%18 = load i32*, i32** %11
%19 = icmp ne i32* %18, null
br i1 %19, label %32, label %20
20: ; preds = %17, %4
%21 = load i32, i32* %6
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %51
23: ; preds = %20
%24 = load i32*, i32** %11
%25 = icmp eq i32* %24, null
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = load i32*, i32** %11
%28 = load i32, i32* %27
%29 = load i32, i32* %6
%30 = sub nsw i32 %29, 1
%31 = icmp ne i32 %28, %30
br i1 %31, label %32, label %51
32: ; preds = %26, %23, %17
%33 = load i8*, i8** %8
%34 = load i32*, i32** %11
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32*, i32** %11
%38 = load i32, i32* %37
br label %40
39: ; preds = %32
br label %40
40: ; preds = %39, %36
%41 = phi i32 [ %38, %36 ], [ -1, %39 ]
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
br label %48
45: ; preds = %40
%46 = load i32, i32* %6
%47 = sub nsw i32 %46, 1
br label %48
48: ; preds = %45, %44
%49 = phi i32 [ -1, %44 ], [ %47, %45 ]
%50 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %33, i32 %41, i32 %49)
store i32 0, i32* %9
br label %51
51: ; preds = %48, %26, %20
%52 = load %struct.rtrb_traverser*, %struct.rtrb_traverser** %5
%53 = call i32* @rtrb_t_next(%struct.rtrb_traverser* %52)
%54 = load %struct.rtrb_traverser*, %struct.rtrb_traverser** %5
%55 = call i32* @rtrb_t_cur(%struct.rtrb_traverser* %54)
store i32* %55, i32** %10
%56 = load i32*, i32** %10
%57 = icmp eq i32* %56, null
br i1 %57, label %63, label %58
58: ; preds = %51
%59 = load i32*, i32** %10
%60 = load i32, i32* %59
%61 = load i32, i32* %6
%62 = icmp ne i32 %60, %61
br i1 %62, label %63, label %75
63: ; preds = %58, %51
%64 = load i8*, i8** %8
%65 = load i32*, i32** %10
%66 = icmp ne i32* %65, null
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = load i32*, i32** %10
%69 = load i32, i32* %68
br label %71
70: ; preds = %63
br label %71
71: ; preds = %70, %67
%72 = phi i32 [ %69, %67 ], [ -1, %70 ]
%73 = load i32, i32* %6
%74 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %64, i32 %72, i32 %73)
store i32 0, i32* %9
br label %75
75: ; preds = %71, %58
%76 = load %struct.rtrb_traverser*, %struct.rtrb_traverser** %5
%77 = call i32* @rtrb_t_next(%struct.rtrb_traverser* %76)
store i32* %77, i32** %12
%78 = load i32, i32* %6
%79 = load i32, i32* %7
%80 = sub nsw i32 %79, 1
%81 = icmp eq i32 %78, %80
br i1 %81, label %82, label %85
82: ; preds = %75
%83 = load i32*, i32** %12
%84 = icmp ne i32* %83, null
br i1 %84, label %99, label %85
85: ; preds = %82, %75
%86 = load i32, i32* %6
%87 = load i32, i32* %7
%88 = sub nsw i32 %87, 1
%89 = icmp ne i32 %86, %88
br i1 %89, label %90, label %120
90: ; preds = %85
%91 = load i32*, i32** %12
%92 = icmp eq i32* %91, null
br i1 %92, label %99, label %93
93: ; preds = %90
%94 = load i32*, i32** %12
%95 = load i32, i32* %94
%96 = load i32, i32* %6
%97 = add nsw i32 %96, 1
%98 = icmp ne i32 %95, %97
br i1 %98, label %99, label %120
99: ; preds = %93, %90, %82
%100 = load i8*, i8** %8
%101 = load i32*, i32** %12
%102 = icmp ne i32* %101, null
br i1 %102, label %103, label %106
103: ; preds = %99
%104 = load i32*, i32** %12
%105 = load i32, i32* %104
br label %107
106: ; preds = %99
br label %107
107: ; preds = %106, %103
%108 = phi i32 [ %105, %103 ], [ -1, %106 ]
%109 = load i32, i32* %6
%110 = load i32, i32* %7
%111 = sub nsw i32 %110, 1
%112 = icmp eq i32 %109, %111
br i1 %112, label %113, label %114
113: ; preds = %107
br label %117
114: ; preds = %107
%115 = load i32, i32* %6
%116 = add nsw i32 %115, 1
br label %117
117: ; preds = %114, %113
%118 = phi i32 [ -1, %113 ], [ %116, %114 ]
%119 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %100, i32 %108, i32 %118)
store i32 0, i32* %9
br label %120
120: ; preds = %117, %93, %85
%121 = load %struct.rtrb_traverser*, %struct.rtrb_traverser** %5
%122 = call i32* @rtrb_t_prev(%struct.rtrb_traverser* %121)
%123 = load i32, i32* %9
ret i32 %123
}

LLVM IR (-O2):
%struct.rtrb_traverser = type { i32 }
@.str = [57 x i8] c" %s traverser ahead of %d, but should be ahead of %d.\0A\00"
@.str.1 = [45 x i8] c" %s traverser at %d, but should be at %d.\0A\00"
@.str.2 = [53 x i8] c" %s traverser behind %d, but should be behind %d.\0A\00"
define i32 @check_traverser(%struct.rtrb_traverser* %0, i32 %1, i32 %2, i8* %3) {
%5 = tail call i32* @rtrb_t_prev(%struct.rtrb_traverser* %0)
%6 = icmp eq i32 %1, 0
%7 = icmp ne i32* %5, null
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %17, label %9
9: ; preds = %4
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %24
11: ; preds = %9
%12 = icmp eq i32* %5, null
br i1 %12, label %17, label %13
13: ; preds = %11
%14 = load i32, i32* %5
%15 = add nsw i32 %1, -1
%16 = icmp eq i32 %14, %15
br i1 %16, label %24, label %17
17: ; preds = %4, %13, %11
br i1 %7, label %18, label %20
18: ; preds = %17
%19 = load i32, i32* %5
br label %20
20: ; preds = %17, %18
%21 = phi i32 [ %19, %18 ], [ -1, %17 ]
%22 = add nsw i32 %1, -1
%23 = tail call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %21, i32 %22)
br label %24
24: ; preds = %20, %13, %9
%25 = phi i32 [ 0, %20 ], [ 1, %13 ], [ 1, %9 ]
%26 = tail call i32* @rtrb_t_next(%struct.rtrb_traverser* %0)
%27 = tail call i32* @rtrb_t_cur(%struct.rtrb_traverser* %0)
%28 = icmp eq i32* %27, null
br i1 %28, label %32, label %29
29: ; preds = %24
%30 = load i32, i32* %27
%31 = icmp eq i32 %30, %1
br i1 %31, label %35, label %32
32: ; preds = %29, %24
%33 = phi i32 [ -1, %24 ], [ %30, %29 ]
%34 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %33, i32 %1)
br label %35
35: ; preds = %32, %29
%36 = phi i32 [ 0, %32 ], [ %25, %29 ]
%37 = tail call i32* @rtrb_t_next(%struct.rtrb_traverser* %0)
%38 = add nsw i32 %2, -1
%39 = icmp eq i32 %38, %1
%40 = icmp ne i32* %37, null
%41 = select i1 %39, i1 %40, i1 false
br i1 %41, label %49, label %42
42: ; preds = %35
br i1 %39, label %57, label %43
43: ; preds = %42
%44 = icmp eq i32* %37, null
br i1 %44, label %49, label %45
45: ; preds = %43
%46 = load i32, i32* %37
%47 = add nsw i32 %1, 1
%48 = icmp eq i32 %46, %47
br i1 %48, label %57, label %49
49: ; preds = %35, %45, %43
br i1 %40, label %50, label %52
50: ; preds = %49
%51 = load i32, i32* %37
br label %52
52: ; preds = %49, %50
%53 = phi i32 [ %51, %50 ], [ -1, %49 ]
%54 = add nsw i32 %1, 1
%55 = select i1 %39, i32 -1, i32 %54
%56 = tail call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 %53, i32 %55)
br label %57
57: ; preds = %52, %45, %42
%58 = phi i32 [ 0, %52 ], [ %36, %45 ], [ %36, %42 ]
%59 = tail call i32* @rtrb_t_prev(%struct.rtrb_traverser* %0)
ret i32 %58
}