#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 */
long evalmdr();
scalar_t__ test(char *);
long evalsum() {
  long val;
  for (val = evalmdr();;) {
    if (test("+"))
      val = val + evalmdr();
    else if (test("-"))
      val = val - evalmdr();
    else
      break;
  }
  return (val);
}


x86 assembly (clang, -O0):
<evalsum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <evalmdr@plt>
mov    %rax,-0x8(%rbp)
lea    0xec6(%rip),%rdi
call   1040 <test@plt>
cmp    $0x0,%rax
je     116b <evalsum+0x4b>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <evalmdr@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11ad <evalsum+0x8d>
lea    0xe90(%rip),%rdi
call   1040 <test@plt>
cmp    $0x0,%rax
je     11a3 <evalsum+0x83>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <evalmdr@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <evalsum+0x88>
jmp    11b2 <evalsum+0x92>
jmp    11ad <evalsum+0x8d>
jmp    1133 <evalsum+0x13>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evalsum>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <evalmdr@plt>
mov    %rax,%rbx
lea    0xeca(%rip),%r14
lea    0xec5(%rip),%r15
jmp    114a <evalsum+0x2a>
nop
xor    %eax,%eax
call   1030 <evalmdr@plt>
add    %rax,%rbx
mov    %r14,%rdi
call   1040 <test@plt>
test   %rax,%rax
jne    1140 <evalsum+0x20>
mov    %r15,%rdi
call   1040 <test@plt>
test   %rax,%rax
je     1170 <evalsum+0x50>
xor    %eax,%eax
call   1030 <evalmdr@plt>
sub    %rax,%rbx
jmp    114a <evalsum+0x2a>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"+\00"
@.str.1 = [2 x i8] c"-\00"
define i64 @evalsum() {
%1 = alloca i64
%2 = call i64 (...) @evalmdr()
store i64 %2, i64* %1
br label %3
3: ; preds = %19, %0
%4 = call i64 @test(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %3
%7 = load i64, i64* %1
%8 = call i64 (...) @evalmdr()
%9 = add nsw i64 %7, %8
store i64 %9, i64* %1
br label %19
10: ; preds = %3
%11 = call i64 @test(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = load i64, i64* %1
%15 = call i64 (...) @evalmdr()
%16 = sub nsw i64 %14, %15
store i64 %16, i64* %1
br label %18
17: ; preds = %10
br label %20
18: ; preds = %13
br label %19
19: ; preds = %18, %6
br label %3
20: ; preds = %17
%21 = load i64, i64* %1
ret i64 %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"+\00"
@.str.1 = [2 x i8] c"-\00"
define i64 @evalsum() {
%1 = tail call i64 (...) @evalmdr()
br label %2
2: ; preds = %15, %0
%3 = phi i64 [ %1, %0 ], [ %16, %15 ]
%4 = tail call i64 @test(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i64 (...) @evalmdr()
%8 = add nsw i64 %7, %3
br label %15
9: ; preds = %2
%10 = tail call i64 @test(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = tail call i64 (...) @evalmdr()
%14 = sub nsw i64 %3, %13
br label %15
15: ; preds = %12, %6
%16 = phi i64 [ %8, %6 ], [ %14, %12 ]
br label %2
17: ; preds = %9
ret i64 %3
}