#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 EOF;
int getop(char *);
int /*<<< orphan*/ printf(char *, ...);
main() {
  int type;
  char s[5 + 1];
  printf("\n>type some operands or operators; blanks are skiped; terminate by "
         "typing Q\n\n");
  while ((type = getop(s)) != EOF) {
    switch (type) {
    case 0:
      printf("operand : %s\n", s);
      break;
    case -3:
      printf("ERROR --- getop() failed to read a number (MAXOP=%i): %s\n", 5,
             s);
      break;
    case '+':
    case '-':
    case '*':
    case '/':
      printf("operator: %c\n", type);
      break;
    case ' ':
    case '\t':
    case '\n':
      break;
    case 'Q':
      return 0;
    default:
      printf("error --- not recognized character %s\n", s);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0x101e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0xe(%rbp),%rdi
call   1040 <getop@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e98(%rip),%rcx
cmp    (%rcx),%eax
je     11f2 <main+0xd2>
mov    -0x8(%rbp),%eax
add    $0x3,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x54,%eax
ja     11db <main+0xbb>
mov    -0x18(%rbp),%rax
lea    0xe88(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    -0xe(%rbp),%rsi
lea    0x1016(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ed <main+0xcd>
lea    -0xe(%rbp),%rdx
lea    0x100d(%rip),%rdi
mov    $0x5,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ed <main+0xcd>
mov    -0x8(%rbp),%esi
lea    0x102c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ed <main+0xcd>
jmp    11ed <main+0xcd>
movl   $0x0,-0x4(%rbp)
jmp    11f2 <main+0xd2>
lea    -0xe(%rbp),%rsi
lea    0x1012(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113d <main+0x1d>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0x108f(%rip),%rdi
call   1030 <puts@plt>
lea    0x2(%rsp),%rdi
call   1050 <getop@plt>
mov    0x2e90(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    116e <main+0x3e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x2(%rsp),%rbx
lea    0xe86(%rip),%r14
lea    0xfe1(%rip),%r15
lea    0xfcc(%rip),%r12
lea    0x100d(%rip),%r13
jmp    11bd <main+0x8d>
lea    0x1012(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <getop@plt>
cmp    0x0(%rbp),%eax
je     115d <main+0x2d>
lea    0x3(%rax),%ecx
cmp    $0x54,%ecx
ja     1191 <main+0x61>
movslq (%r14,%rcx,4),%rcx
add    %r14,%rcx
jmp    *%rcx
mov    %r13,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b0 <main+0x80>
mov    %r15,%rdi
mov    $0x5,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11b0 <main+0x80>
mov    %r12,%rdi
jmp    1198 <main+0x68>

LLVM IR (-O0):
@.str = [78 x i8] c"\0A>type some operands or operators; blanks are skiped; terminate by typing Q\0A\0A\00"
@EOF = global i32 0
@.str.1 = [14 x i8] c"operand : %s\0A\00"
@.str.2 = [58 x i8] c"ERROR --- getop() failed to read a number (MAXOP=%i): %s\0A\00"
@.str.3 = [14 x i8] c"operator: %c\0A\00"
@.str.4 = [39 x i8] c"error --- not recognized character %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [6 x i8]
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([78 x i8], [78 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %26, %0
%6 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%7 = call i32 @getop(i8* %6)
store i32 %7, i32* %2
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %27
10: ; preds = %5
%11 = load i32, i32* %2
switch i32 %11, label %23 [
i32 0, label %12
i32 -3, label %15
i32 43, label %18
i32 45, label %18
i32 42, label %18
i32 47, label %18
i32 32, label %21
i32 9, label %21
i32 10, label %21
i32 81, label %22
]
12: ; preds = %10
%13 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %26
15: ; preds = %10
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i32 5, i8* %16)
br label %26
18: ; preds = %10, %10, %10, %10
%19 = load i32, i32* %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %19)
br label %26
21: ; preds = %10, %10, %10
br label %26
22: ; preds = %10
store i32 0, i32* %1
br label %27
23: ; preds = %10
%24 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %23, %21, %18, %15, %12
br label %5
27: ; preds = %22, %5
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
@EOF = global i32 0
@.str.1 = [14 x i8] c"operand : %s\0A\00"
@.str.2 = [58 x i8] c"ERROR --- getop() failed to read a number (MAXOP=%i): %s\0A\00"
@.str.3 = [14 x i8] c"operator: %c\0A\00"
@.str.4 = [39 x i8] c"error --- not recognized character %s\0A\00"
@str = [77 x i8] c"\0A>type some operands or operators; blanks are skiped; terminate by typing Q\0A\00"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @str, i64 0, i64 0))
%4 = call i32 @getop(i8* %2)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %21, label %7
7: ; preds = %0, %17
%8 = phi i32 [ %18, %17 ], [ %4, %0 ]
switch i32 %8, label %15 [
i32 0, label %9
i32 -3, label %11
i32 43, label %13
i32 45, label %13
i32 42, label %13
i32 47, label %13
i32 32, label %17
i32 9, label %17
i32 10, label %17
i32 81, label %21
]
9: ; preds = %7
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %17
11: ; preds = %7
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0), i32 5, i8* %2)
br label %17
13: ; preds = %7, %7, %7, %7
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %8)
br label %17
15: ; preds = %7
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %17
17: ; preds = %7, %7, %7, %15, %13, %11, %9
%18 = call i32 @getop(i8* %2)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %7
21: ; preds = %7, %17, %0
ret i32 0
}