#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*/ scanf(char *, int *, int *, int *);
int next(int *current, int cap) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  if (a > *current)
    return 0;
  *current -= a;
  if (*current + b > cap)
    return 0;
  *current += b;
  if (c > 0 && *current != cap)
    return 0;
}


x86 assembly (clang, -O0):
<next>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    0xeda(%rip),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1030 <scanf@plt>
mov    -0x18(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    1152 <next+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <next+0x98>
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    117d <next+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    11a8 <next+0x98>
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
cmpl   $0x0,-0x20(%rbp)
jle    11a8 <next+0x98>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
je     11a8 <next+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0xede(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
lea    0x14(%rsp),%rcx
call   1030 <scanf@plt>
mov    (%rbx),%eax
sub    0x10(%rsp),%eax
jl     114b <next+0x3b>
mov    0xc(%rsp),%ecx
add    %eax,%ecx
cmp    %ebp,%ecx
cmovg  %eax,%ecx
mov    %ecx,(%rbx)
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d %d %d\00"
define i32 @next(i32* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32 %1, i32* %5
%9 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7, i32* %8)
%10 = load i32, i32* %6
%11 = load i32*, i32** %4
%12 = load i32, i32* %11
%13 = icmp sgt i32 %10, %12
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 0, i32* %3
br label %40
15: ; preds = %2
%16 = load i32, i32* %6
%17 = load i32*, i32** %4
%18 = load i32, i32* %17
%19 = sub nsw i32 %18, %16
store i32 %19, i32* %17
%20 = load i32*, i32** %4
%21 = load i32, i32* %20
%22 = load i32, i32* %7
%23 = add nsw i32 %21, %22
%24 = load i32, i32* %5
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %15
store i32 0, i32* %3
br label %40
27: ; preds = %15
%28 = load i32, i32* %7
%29 = load i32*, i32** %4
%30 = load i32, i32* %29
%31 = add nsw i32 %30, %28
store i32 %31, i32* %29
%32 = load i32, i32* %8
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %27
%35 = load i32*, i32** %4
%36 = load i32, i32* %35
%37 = load i32, i32* %5
%38 = icmp ne i32 %36, %37
br i1 %38, label %39, label %40
39: ; preds = %34
store i32 0, i32* %3
br label %40
40: ; preds = %14, %26, %39, %34, %27
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d %d %d\00"
define i32 @next(i32* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4, i32* %5)
%10 = load i32, i32* %3
%11 = load i32, i32* %0
%12 = icmp slt i32 %11, %10
br i1 %12, label %19, label %13
13: ; preds = %2
%14 = sub nsw i32 %11, %10
%15 = load i32, i32* %4
%16 = add nsw i32 %15, %14
%17 = icmp sgt i32 %16, %1
%18 = select i1 %17, i32 %14, i32 %16
store i32 %18, i32* %0
br label %19
19: ; preds = %13, %2
ret i32 0
}