#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*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ operation(char *, char *, char);
int /*<<< orphan*/ printf(char *);
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char *strsep(char **, char *);
void calculate(char *s) {
  char *op1, *op2, *op, oper[2];
  int op1Len;
  op = strchr(s, '+');
  if (!op) {
    op = strchr(s, '-');
  }
  oper[0] = op[0];
  oper[1] = 0;
  if (!op) {
    printf("Couldnt find the operators\n");
    return;
  }
  op1 = strsep(&s, oper);
  op2 = s;
  strcpy(s + 1200, op2);
  op1Len = strlen(op1);
  memset(op1 + op1Len, 0, 1200 - op1Len - 1);
  op2 = s + 1200;
  operation(op1, op2, oper[0]);
}


x86 assembly (clang, -O0):
<calculate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2b,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ab <calculate+0x3b>
mov    -0x8(%rbp),%rdi
mov    $0x2d,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x22(%rbp)
movb   $0x0,-0x21(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d4 <calculate+0x64>
lea    0xe36(%rip),%rdi
call   1060 <printf@plt>
jmp    1249 <calculate+0xd9>
lea    -0x22(%rbp),%rsi
lea    -0x8(%rbp),%rdi
call   1090 <strsep@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x4b0,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    $0x4b0,%edx
sub    -0x28(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x8(%rbp),%rax
add    $0x4b0,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsbl -0x22(%rbp),%edx
call   1080 <operation@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rdi,0x8(%rsp)
mov    $0x2b,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    1189 <calculate+0x29>
mov    %rbx,%rdi
mov    $0x2d,%esi
call   1050 <strchr@plt>
mov    (%rax),%al
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
lea    0x8(%rsp),%rdi
lea    0x6(%rsp),%rsi
call   1080 <strsep@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
lea    0x4b0(%rsi),%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rdi
mov    $0x4af,%edx
sub    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x4b0,%esi
add    0x8(%rsp),%rsi
movsbl 0x6(%rsp),%edx
mov    %rbx,%rdi
call   1070 <operation@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Couldnt find the operators\0A\00"
define void @calculate(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [2 x i8]
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i8* @strchr(i8* %8, i8 signext 43)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i8* @strchr(i8* %13, i8 signext 45)
store i8* %14, i8** %5
br label %15
15: ; preds = %12, %1
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
store i8 %18, i8* %19
%20 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 0, i8* %20
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %25, label %23
23: ; preds = %15
%24 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %50
25: ; preds = %15
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%27 = call i8* @strsep(i8** %2, i8* %26)
store i8* %27, i8** %3
%28 = load i8*, i8** %2
store i8* %28, i8** %4
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i64 1200
%31 = load i8*, i8** %4
%32 = call i32 @strcpy(i8* %30, i8* %31)
%33 = load i8*, i8** %3
%34 = call i32 @strlen(i8* %33)
store i32 %34, i32* %7
%35 = load i8*, i8** %3
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i32, i32* %7
%40 = sub nsw i32 1200, %39
%41 = sub nsw i32 %40, 1
%42 = call i32 @memset(i8* %38, i32 0, i32 %41)
%43 = load i8*, i8** %2
%44 = getelementptr inbounds i8, i8* %43, i64 1200
store i8* %44, i8** %4
%45 = load i8*, i8** %3
%46 = load i8*, i8** %4
%47 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%48 = load i8, i8* %47
%49 = call i32 @operation(i8* %45, i8* %46, i8 signext %48)
br label %50
50: ; preds = %25, %23
ret void
}

LLVM IR (-O2):
define void @calculate(i8* %0) {
%2 = alloca i8*
%3 = alloca [2 x i8]
store i8* %0, i8** %2
%4 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%5 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 43)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 45)
br label %9
9: ; preds = %7, %1
%10 = phi i8* [ %5, %1 ], [ %8, %7 ]
%11 = load i8, i8* %10
store i8 %11, i8* %4
%12 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
store i8 0, i8* %12
%13 = call i8* @strsep(i8** %2, i8* %4)
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i64 1200
%16 = call i32 @strcpy(i8* %15, i8* %14)
%17 = call i32 @strlen(i8* %13)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %13, i64 %18
%20 = sub i32 1199, %17
%21 = call i32 @memset(i8* %19, i32 0, i32 %20)
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i64 1200
%24 = load i8, i8* %4
%25 = call i32 @operation(i8* %13, i8* %23, i8 signext %24)
ret void
}