#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 plan_count_entries(char const *);
int plan_get_entry(char const *);
int /*<<< orphan*/ plan_set_entry(char const *, int);
void next(const char *plan) {
  int entries = plan_count_entries(plan);
  int entry = plan_get_entry(plan);
  plan_set_entry(plan, ((entry + 1) < (1)             ? (1)
                        : (entry + 1) > (entries + 1) ? (entries + 1)
                                                      : (entry + 1)));
}


x86 assembly (clang, -O0):
<next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <plan_count_entries@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <plan_get_entry@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cmp    $0x1,%eax
jge    1178 <next+0x48>
mov    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a9 <next+0x79>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    119a <next+0x6a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11a3 <next+0x73>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <plan_set_entry@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <plan_count_entries@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <plan_get_entry@plt>
lea    0x1(%rax),%ecx
add    $0x1,%ebp
cmp    %ebp,%ecx
cmovle %ecx,%ebp
test   %eax,%eax
mov    $0x1,%esi
cmovns %ebp,%esi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <plan_set_entry@plt>

LLVM IR (-O0):
define void @next(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @plan_count_entries(i8* %5)
store i32 %6, i32* %3
%7 = load i8*, i8** %2
%8 = call i32 @plan_get_entry(i8* %7)
store i32 %8, i32* %4
%9 = load i8*, i8** %2
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %14
13: ; preds = %1
br label %28
14: ; preds = %1
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
%19 = icmp sgt i32 %16, %18
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
br label %26
23: ; preds = %14
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
br label %26
26: ; preds = %23, %20
%27 = phi i32 [ %22, %20 ], [ %25, %23 ]
br label %28
28: ; preds = %26, %13
%29 = phi i32 [ 1, %13 ], [ %27, %26 ]
%30 = call i32 @plan_set_entry(i8* %9, i32 %29)
ret void
}

LLVM IR (-O2):
define void @next(i8* %0) {
%2 = tail call i32 @plan_count_entries(i8* %0)
%3 = tail call i32 @plan_get_entry(i8* %0)
%4 = add nsw i32 %3, 1
%5 = icmp slt i32 %3, 0
%6 = add nsw i32 %2, 1
%7 = icmp sgt i32 %4, %6
%8 = select i1 %7, i32 %6, i32 %4
%9 = select i1 %5, i32 1, i32 %8
%10 = tail call i32 @plan_set_entry(i8* %0, i32 %9)
ret void
}