#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 matoi(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
long sfix(const char *str, const long cur, const long max) {
  if (!strncmp(str, "max", 8))
    return max;
  else
    return matoi(str) + (str[0] == '+' || str[0] == '-' ? cur : 0);
}


x86 assembly (clang, -O0):
<sfix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xec1(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    115f <sfix+0x3f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b3 <sfix+0x93>
mov    -0x10(%rbp),%rdi
call   1040 <matoi@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
je     118c <sfix+0x6c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1199 <sfix+0x79>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11a4 <sfix+0x84>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11a4 <sfix+0x84>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sfix>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xecb(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1160 <sfix+0x40>
mov    %rbx,%rdi
call   1040 <matoi@plt>
mov    (%rbx),%cl
cmp    $0x2d,%cl
je     115a <sfix+0x3a>
cmp    $0x2b,%cl
je     115a <sfix+0x3a>
xor    %r14d,%r14d
add    %rax,%r14
mov    %r14,%r15
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"max\00"
define i64 @sfix(i8* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%8 = load i8*, i8** %5
%9 = call i32 @strncmp(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = load i64, i64* %7
store i64 %12, i64* %4
br label %33
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i64 @matoi(i8* %14)
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 43
br i1 %20, label %27, label %21
21: ; preds = %13
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 45
br i1 %26, label %27, label %29
27: ; preds = %21, %13
%28 = load i64, i64* %6
br label %30
29: ; preds = %21
br label %30
30: ; preds = %29, %27
%31 = phi i64 [ %28, %27 ], [ 0, %29 ]
%32 = add nsw i64 %15, %31
store i64 %32, i64* %4
br label %33
33: ; preds = %30, %11
%34 = load i64, i64* %4
ret i64 %34
}

LLVM IR (-O2):
@.str = [4 x i8] c"max\00"
define i64 @sfix(i8* %0, i64 %1, i64 %2) {
%4 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 8)
%5 = icmp eq i32 %4, 0
br i1 %5, label %13, label %6
6: ; preds = %3
%7 = tail call i64 @matoi(i8* %0)
%8 = load i8, i8* %0
switch i8 %8, label %10 [
i8 43, label %9
i8 45, label %9
]
9: ; preds = %6, %6
br label %10
10: ; preds = %6, %9
%11 = phi i64 [ %1, %9 ], [ 0, %6 ]
%12 = add nsw i64 %11, %7
br label %13
13: ; preds = %3, %10
%14 = phi i64 [ %12, %10 ], [ %2, %3 ]
ret i64 %14
}