#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*/ assert(int /*<<< orphan*/);
int next_result(char *pattern, size_t patt_i, int new_n, int res_so_far) {
  if (patt_i == 0) {
    return new_n;
  }
  switch (pattern[patt_i - 1]) {
  case '+':
    return res_so_far + new_n;
  case '-':
    return res_so_far - new_n;
  default:
    assert(0);
  }
}


x86 assembly (clang, -O0):
<next_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    113c <next_result+0x2c>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <next_result+0x7e>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
movsbl -0x1(%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
sub    $0x2b,%eax
je     116b <next_result+0x5b>
jmp    115a <next_result+0x4a>
mov    -0x24(%rbp),%eax
sub    $0x2d,%eax
je     1179 <next_result+0x69>
jmp    1187 <next_result+0x77>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <next_result+0x7e>
mov    -0x20(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <next_result+0x7e>
xor    %edi,%edi
call   1030 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_result>:
push   %rax
mov    %edx,%eax
test   %rsi,%rsi
je     1138 <next_result+0x28>
movsbl -0x1(%rsi,%rdi,1),%edx
cmp    $0x2d,%edx
je     112b <next_result+0x1b>
cmp    $0x2b,%edx
jne    1131 <next_result+0x21>
add    %ecx,%eax
pop    %rcx
ret
sub    %eax,%ecx
mov    %ecx,%eax
pop    %rcx
ret
xor    %edi,%edi
call   1030 <assert@plt>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @next_result(i8* %0, i64 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%10 = load i64, i64* %7
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %4
%13 = load i32, i32* %8
store i32 %13, i32* %5
br label %31
14: ; preds = %4
%15 = load i8*, i8** %6
%16 = load i64, i64* %7
%17 = sub i64 %16, 1
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
switch i32 %20, label %29 [
i32 43, label %21
i32 45, label %25
]
21: ; preds = %14
%22 = load i32, i32* %9
%23 = load i32, i32* %8
%24 = add nsw i32 %22, %23
store i32 %24, i32* %5
br label %31
25: ; preds = %14
%26 = load i32, i32* %9
%27 = load i32, i32* %8
%28 = sub nsw i32 %26, %27
store i32 %28, i32* %5
br label %31
29: ; preds = %14
%30 = call i32 @assert(i32 0)
br label %31
31: ; preds = %12, %21, %25, %29
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
define i32 @next_result(i8* nocapture %0, i64 %1, i32 %2, i32 %3) {
%5 = icmp eq i64 %1, 0
br i1 %5, label %17, label %6
6: ; preds = %4
%7 = add i64 %1, -1
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %15 [
i32 43, label %11
i32 45, label %13
]
11: ; preds = %6
%12 = add nsw i32 %3, %2
br label %17
13: ; preds = %6
%14 = sub nsw i32 %3, %2
br label %17
15: ; preds = %6
%16 = tail call i32 @assert(i32 0)
br label %17
17: ; preds = %4, %11, %13, %15
%18 = phi i32 [ undef, %15 ], [ %14, %13 ], [ %12, %11 ], [ %2, %4 ]
ret i32 %18
}