#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int num1, num2;
  char opt;
  printf("Please write +, - or x\n");
  scanf("%c", &opt);
  printf("Write your two number\n");
  scanf("%d%d", &num1, &num2);
  switch (opt) {
  case '+':
    printf("%.1d + %.1d = %.1d", num1, num2, num1 + num2);
    break;
  case '-':
    printf("%.1d - %.1d = %.1d", num1, num2, num1 - num2);
    break;
  case 'x':
    printf("%.1d * %.1d = %.1d", num1, num2, num1 * num2);
    break;
  default:
    printf("write again");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x15(%rbp)
call   1030 <printf@plt>
mov    -0x15(%rbp),%al
lea    0xece(%rip),%rdi
lea    -0xd(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x15(%rbp),%al
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
mov    -0x15(%rbp),%al
lea    0xec6(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <scanf@plt>
movsbl -0xd(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x2b,%eax
je     11b0 <main+0x90>
jmp    118e <main+0x6e>
mov    -0x14(%rbp),%eax
sub    $0x2d,%eax
je     11cf <main+0xaf>
jmp    119f <main+0x7f>
mov    -0x14(%rbp),%eax
sub    $0x78,%eax
je     11ee <main+0xce>
jmp    120e <main+0xee>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
add    -0xc(%rbp),%ecx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121c <main+0xfc>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
sub    -0xc(%rbp),%ecx
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121c <main+0xfc>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%ecx
imul   -0xc(%rbp),%ecx
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    121c <main+0xfc>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0xf12(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb9(%rip),%rdi
lea    0xf(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
lea    0xf0a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9d(%rip),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
movsbl 0xf(%rsp),%eax
cmp    $0x78,%eax
je     119f <main+0x6f>
cmp    $0x2d,%eax
je     11b5 <main+0x85>
cmp    $0x2b,%eax
jne    11d1 <main+0xa1>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
lea    (%rdx,%rsi,1),%ecx
lea    0xe6b(%rip),%rdi
jmp    11c8 <main+0x98>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %edx,%ecx
imul   %esi,%ecx
lea    0xe7b(%rip),%rdi
jmp    11c8 <main+0x98>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %esi,%ecx
sub    %edx,%ecx
lea    0xe53(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11df <main+0xaf>
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Please write +, - or x\0A\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [23 x i8] c"Write your two number\0A\00"
@.str.3 = [5 x i8] c"%d%d\00"
@.str.4 = [19 x i8] c"%.1d + %.1d = %.1d\00"
@.str.5 = [19 x i8] c"%.1d - %.1d = %.1d\00"
@.str.6 = [19 x i8] c"%.1d * %.1d = %.1d\00"
@.str.7 = [12 x i8] c"write again\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %2, i32* %3)
%9 = load i8, i8* %4
%10 = sext i8 %9 to i32
switch i32 %10, label %32 [
i32 43, label %11
i32 45, label %18
i32 120, label %25
]
11: ; preds = %0
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = load i32, i32* %3
%16 = add nsw i32 %14, %15
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %12, i32 %13, i32 %16)
br label %34
18: ; preds = %0
%19 = load i32, i32* %2
%20 = load i32, i32* %3
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = sub nsw i32 %21, %22
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %19, i32 %20, i32 %23)
br label %34
25: ; preds = %0
%26 = load i32, i32* %2
%27 = load i32, i32* %3
%28 = load i32, i32* %2
%29 = load i32, i32* %3
%30 = mul nsw i32 %28, %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %26, i32 %27, i32 %30)
br label %34
32: ; preds = %0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %34
34: ; preds = %32, %25, %18, %11
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%c\00"
@.str.3 = [5 x i8] c"%d%d\00"
@.str.4 = [19 x i8] c"%.1d + %.1d = %.1d\00"
@.str.5 = [19 x i8] c"%.1d - %.1d = %.1d\00"
@.str.6 = [19 x i8] c"%.1d * %.1d = %.1d\00"
@.str.7 = [12 x i8] c"write again\00"
@str = [23 x i8] c"Please write +, - or x\00"
@str.8 = [22 x i8] c"Write your two number\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
%9 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32* %1, i32* %2)
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
switch i32 %11, label %27 [
i32 43, label %12
i32 45, label %17
i32 120, label %22
]
12: ; preds = %0
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = add nsw i32 %14, %13
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %13, i32 %14, i32 %15)
br label %29
17: ; preds = %0
%18 = load i32, i32* %1
%19 = load i32, i32* %2
%20 = sub nsw i32 %18, %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %18, i32 %19, i32 %20)
br label %29
22: ; preds = %0
%23 = load i32, i32* %1
%24 = load i32, i32* %2
%25 = mul nsw i32 %24, %23
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i32 %23, i32 %24, i32 %25)
br label %29
27: ; preds = %0
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %29
29: ; preds = %27, %22, %17, %12
ret i32 0
}