#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int a;
  int b;
  int result;
  char op;
  if (argc != 4) {
    printf("Invalid parameters. Usage:\n");
    printf("scalc <operand> <operator> <operand>\n");
    printf("operand should be integers, and operator one of +, -, * or /.\n");
    exit(1);
  }
  a = atoi(argv[1]);
  op = argv[2][0];
  b = atoi(argv[3]);
  switch (op) {
  case '+':
    result = a + b;
    break;
  case '-':
    result = a - b;
    break;
  case '*':
    result = a * b;
    break;
  case '/':
    if (b != 0) {
      result = a / b;
      break;
    }
  default:
    printf("Invalid operation!\n");
    exit(2);
  }
  printf("%d\n", result);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1184 <main+0x54>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xee7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x18(%rbp)
movsbl -0x1d(%rbp),%eax
add    $0xffffffd6,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x5,%eax
ja     1224 <main+0xf4>
mov    -0x28(%rbp),%rax
lea    0xe2e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    123c <main+0x10c>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    123c <main+0x10c>
mov    -0x14(%rbp),%eax
imul   -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    123c <main+0x10c>
cmpl   $0x0,-0x18(%rbp)
je     121f <main+0xef>
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,-0x1c(%rbp)
jmp    123c <main+0x10c>
jmp    1224 <main+0xf4>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x2,%edi
call   1050 <exit@plt>
mov    -0x1c(%rbp),%esi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    11b1 <main+0x71>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rax
mov    0x18(%rbx),%rdi
movsbl (%rax),%ebx
call   1050 <atoi@plt>
add    $0xffffffd6,%ebx
cmp    $0x5,%ebx
ja     11df <main+0x9f>
mov    %eax,%esi
lea    0xe89(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
imul   %ebp,%esi
jmp    119a <main+0x5a>
add    %ebp,%esi
jmp    119a <main+0x5a>
sub    %esi,%ebp
mov    %ebp,%esi
jmp    119a <main+0x5a>
test   %esi,%esi
je     11df <main+0x9f>
mov    %ebp,%eax
cltd
idiv   %esi
mov    %eax,%esi
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
lea    0xe86(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
lea    0xe36(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Invalid parameters. Usage:\0A\00"
@.str.1 = [38 x i8] c"scalc <operand> <operator> <operand>\0A\00"
@.str.2 = [63 x i8] c"operand should be integers, and operator one of +, -, * or /.\0A\00"
@.str.3 = [20 x i8] c"Invalid operation!\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
store i32 %21, i32* %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = getelementptr inbounds i8, i8* %24, i64 0
%26 = load i8, i8* %25
store i8 %26, i8* %9
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %7
%31 = load i8, i8* %9
%32 = sext i8 %31 to i32
switch i32 %32, label %53 [
i32 43, label %33
i32 45, label %37
i32 42, label %41
i32 47, label %45
]
33: ; preds = %17
%34 = load i32, i32* %6
%35 = load i32, i32* %7
%36 = add nsw i32 %34, %35
store i32 %36, i32* %8
br label %56
37: ; preds = %17
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = sub nsw i32 %38, %39
store i32 %40, i32* %8
br label %56
41: ; preds = %17
%42 = load i32, i32* %6
%43 = load i32, i32* %7
%44 = mul nsw i32 %42, %43
store i32 %44, i32* %8
br label %56
45: ; preds = %17
%46 = load i32, i32* %7
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %45
%49 = load i32, i32* %6
%50 = load i32, i32* %7
%51 = sdiv i32 %49, %50
store i32 %51, i32* %8
br label %56
52: ; preds = %45
br label %53
53: ; preds = %17, %52
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%55 = call i32 @exit(i32 2)
unreachable
56: ; preds = %48, %41, %37, %33
%57 = load i32, i32* %8
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %57)
ret i32 0
}

LLVM IR (-O2):
@.str.4 = [4 x i8] c"%d\0A\00"
@str = [19 x i8] c"Invalid operation!\00"
@str.5 = [27 x i8] c"Invalid parameters. Usage:\00"
@str.6 = [37 x i8] c"scalc <operand> <operator> <operand>\00"
@str.7 = [62 x i8] c"operand should be integers, and operator one of +, -, * or /.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.5, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.6, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str.7, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8*, i8** %1, i64 3
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = sext i8 %15 to i32
switch i32 %19, label %30 [
i32 43, label %20
i32 45, label %22
i32 42, label %24
i32 47, label %26
]
20: ; preds = %9
%21 = add nsw i32 %18, %12
br label %33
22: ; preds = %9
%23 = sub nsw i32 %12, %18
br label %33
24: ; preds = %9
%25 = mul nsw i32 %18, %12
br label %33
26: ; preds = %9
%27 = icmp eq i32 %18, 0
br i1 %27, label %30, label %28
28: ; preds = %26
%29 = sdiv i32 %12, %18
br label %33
30: ; preds = %26, %9
%31 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%32 = tail call i32 @exit(i32 2)
unreachable
33: ; preds = %28, %24, %22, %20
%34 = phi i32 [ %29, %28 ], [ %25, %24 ], [ %23, %22 ], [ %21, %20 ]
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %34)
ret i32 0
}