#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 variablelist {
  int dummy;
};
struct union_number {
  int dummy;
};

/* Variables and functions */
int EINVAL;
int incalc(char const **, struct variablelist *, struct union_number *);
scalar_t__ isspace(char const);
int calcnest(const char **str, struct variablelist *arg,
             struct union_number *ret) {
  int err;
  err = incalc(str, arg, ret);
  if (err)
    return err;
  while (isspace(**str))
    (*str)++;
  if (**str != ')')
    return -EINVAL;
  (*str)++;
  return 0;
}


x86 assembly (clang, -O0):
<calcnest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <incalc@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     115d <calcnest+0x3d>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c9 <calcnest+0xa9>
jmp    1162 <calcnest+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     118e <calcnest+0x6e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1162 <calcnest+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x29,%eax
je     11b4 <calcnest+0x94>
xor    %eax,%eax
mov    0x2e36(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11c9 <calcnest+0xa9>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcnest>:
push   %rbx
mov    %rdi,%rbx
call   1030 <incalc@plt>
test   %eax,%eax
je     112f <calcnest+0xf>
pop    %rbx
ret
mov    (%rbx),%rax
movsbl (%rax),%edi
cs nopw 0x0(%rax,%rax,1)
nop
call   1040 <isspace@plt>
test   %rax,%rax
je     115a <calcnest+0x3a>
mov    (%rbx),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%rbx)
movsbl 0x1(%rax),%edi
jmp    1140 <calcnest+0x20>
mov    (%rbx),%rax
cmpb   $0x29,(%rax)
jne    116d <calcnest+0x4d>
add    $0x1,%rax
mov    %rax,(%rbx)
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e6c(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.variablelist = type { i32 }
%struct.union_number = type { i32 }
@EINVAL = global i32 0
define i32 @calcnest(i8** %0, %struct.variablelist* %1, %struct.union_number* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.variablelist*
%7 = alloca %struct.union_number*
%8 = alloca i32
store i8** %0, i8*** %5
store %struct.variablelist* %1, %struct.variablelist** %6
store %struct.union_number* %2, %struct.union_number** %7
%9 = load i8**, i8*** %5
%10 = load %struct.variablelist*, %struct.variablelist** %6
%11 = load %struct.union_number*, %struct.union_number** %7
%12 = call i32 @incalc(i8** %9, %struct.variablelist* %10, %struct.union_number* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = load i32, i32* %8
store i32 %16, i32* %4
br label %41
17: ; preds = %3
br label %18
18: ; preds = %24, %17
%19 = load i8**, i8*** %5
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = call i64 @isspace(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %25
br label %18
28: ; preds = %18
%29 = load i8**, i8*** %5
%30 = load i8*, i8** %29
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, 41
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i32, i32* @EINVAL
%36 = sub nsw i32 0, %35
store i32 %36, i32* %4
br label %41
37: ; preds = %28
%38 = load i8**, i8*** %5
%39 = load i8*, i8** %38
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %38
store i32 0, i32* %4
br label %41
41: ; preds = %37, %34, %15
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
%struct.variablelist = type { i32 }
%struct.union_number = type { i32 }
@EINVAL = global i32 0
define i32 @calcnest(i8** %0, %struct.variablelist* %1, %struct.union_number* %2) {
%4 = tail call i32 @incalc(i8** %0, %struct.variablelist* %1, %struct.union_number* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %26
6: ; preds = %3
%7 = load i8*, i8** %0
%8 = load i8, i8* %7
%9 = tail call i64 @isspace(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %6, %11
%12 = load i8*, i8** %0
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8* %13, i8** %0
%14 = load i8, i8* %13
%15 = tail call i64 @isspace(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %11
17: ; preds = %11, %6
%18 = load i8*, i8** %0
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 41
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = load i32, i32* @EINVAL
%23 = sub nsw i32 0, %22
br label %26
24: ; preds = %17
%25 = getelementptr inbounds i8, i8* %18, i64 1
store i8* %25, i8** %0
br label %26
26: ; preds = %3, %24, %21
%27 = phi i32 [ %23, %21 ], [ 0, %24 ], [ %4, %3 ]
ret i32 %27
}