#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 next_ops(size_t n, char ops[n]) {
  int i = n - 1;
  while (i >= 0 && ops[i] == '-') {
    ops[i] = '+';
    i--;
  }
  if (i < 0) {
    return 0;
  } else {
    ops[i] = '-';
    return 1;
  }
}


x86 assembly (clang, -O0):
<next_ops>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x1d(%rbp)
jl     113b <next_ops+0x3b>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
sete   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    114b <next_ops+0x4b>
jmp    1165 <next_ops+0x65>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x2b,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1117 <next_ops+0x17>
cmpl   $0x0,-0x1c(%rbp)
jge    117b <next_ops+0x7b>
movl   $0x0,-0x4(%rbp)
jmp    118e <next_ops+0x8e>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x2d,(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_ops>:
xor    %eax,%eax
add    $0xffffffff,%edi
js     1121 <next_ops+0x21>
nopw   0x0(%rax,%rax,1)
mov    %edi,%edi
cmpb   $0x2d,(%rsi,%rdi,1)
jne    1122 <next_ops+0x22>
movb   $0x2b,(%rsi,%rdi,1)
add    $0xffffffff,%edi
jns    1110 <next_ops+0x10>
ret
movb   $0x2d,(%rsi,%rdi,1)
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i32 @next_ops(i64 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i64 %0, i64* %4
store i8* %1, i8** %5
%7 = load i64, i64* %4
%8 = load i64, i64* %4
%9 = sub i64 %8, 1
%10 = trunc i64 %9 to i32
store i32 %10, i32* %6
br label %11
11: ; preds = %24, %2
%12 = load i32, i32* %6
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 45
br label %22
22: ; preds = %14, %11
%23 = phi i1 [ false, %11 ], [ %21, %14 ]
br i1 %23, label %24, label %31
24: ; preds = %22
%25 = load i8*, i8** %5
%26 = load i32, i32* %6
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 43, i8* %28
%29 = load i32, i32* %6
%30 = add nsw i32 %29, -1
store i32 %30, i32* %6
br label %11
31: ; preds = %22
%32 = load i32, i32* %6
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %31
store i32 0, i32* %3
br label %40
35: ; preds = %31
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 45, i8* %39
store i32 1, i32* %3
br label %40
40: ; preds = %35, %34
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @next_ops(i64 %0, i8* nocapture %1) {
%3 = trunc i64 %0 to i32
%4 = add i32 %3, -1
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %16
6: ; preds = %2, %12
%7 = phi i32 [ %13, %12 ], [ %4, %2 ]
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %1, i64 %8
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 45
br i1 %11, label %12, label %15
12: ; preds = %6
store i8 43, i8* %9
%13 = add i32 %7, -1
%14 = icmp sgt i32 %13, -1
br i1 %14, label %6, label %16
15: ; preds = %6
store i8 45, i8* %9
br label %16
16: ; preds = %12, %2, %15
%17 = phi i32 [ 1, %15 ], [ 0, %2 ], [ 0, %12 ]
ret i32 %17
}