#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 curve_points {
  int dummy;
};

/* Variables and functions */
int next_curve(struct curve_points *, int *);
int num_curves(struct curve_points *plot) {
  int curves;
  int first_point;
  int num_points;
  first_point = 0;
  curves = 0;
  while ((num_points = next_curve(plot, &first_point)) > 0) {
    curves++;
    first_point += num_points;
  }
  return (curves);
}


x86 assembly (clang, -O0):
<num_curves>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <next_curve@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    115a <num_curves+0x4a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    112a <num_curves+0x1a>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_curves>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
call   1030 <next_curve@plt>
xor    %ebp,%ebp
test   %eax,%eax
jle    1156 <num_curves+0x46>
lea    0xc(%rsp),%r14
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
add    %eax,0xc(%rsp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <next_curve@plt>
test   %eax,%eax
jg     1140 <num_curves+0x30>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.curve_points = type { i32 }
define i32 @num_curves(%struct.curve_points* %0) {
%2 = alloca %struct.curve_points*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store %struct.curve_points* %0, %struct.curve_points** %2
store i32 0, i32* %4
store i32 0, i32* %3
br label %6
6: ; preds = %10, %1
%7 = load %struct.curve_points*, %struct.curve_points** %2
%8 = call i32 @next_curve(%struct.curve_points* %7, i32* %4)
store i32 %8, i32* %5
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %6
%11 = load i32, i32* %3
%12 = add nsw i32 %11, 1
store i32 %12, i32* %3
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = add nsw i32 %14, %13
store i32 %15, i32* %4
br label %6
16: ; preds = %6
%17 = load i32, i32* %3
ret i32 %17
}

LLVM IR (-O2):
%struct.curve_points = type { i32 }
define i32 @num_curves(%struct.curve_points* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = call i32 @next_curve(%struct.curve_points* %0, i32* %2)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %1, %6
%7 = phi i32 [ %12, %6 ], [ %4, %1 ]
%8 = phi i32 [ %9, %6 ], [ 0, %1 ]
%9 = add nuw nsw i32 %8, 1
%10 = load i32, i32* %2
%11 = add nsw i32 %10, %7
store i32 %11, i32* %2
%12 = call i32 @next_curve(%struct.curve_points* %0, i32* %2)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %6, label %14
14: ; preds = %6, %1
%15 = phi i32 [ 0, %1 ], [ %9, %6 ]
ret i32 %15
}