#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 */
scalar_t__ do_next_op(char, double, double *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scan_data(char *, double *);
int main(void) {
  double akkumulatoren = 0, operand = 0;
  char operator;
  printf("En lille lommeregner.\nHer er de gyldige operationer:\n  +  "
         "addition\n  -  subtraktion\n  *  multiplikation\n  /  division\n  ^  "
         "potensopløftning\n  q  quit\n");
  while (1) {
    scan_data(&operator, & operand);
    if (operator== 'q') {
      break;
    }
    if (do_next_op(operator, operand, &akkumulatoren) != 0) {
      printf(
          "Kan ikke forstå operatoren '%c'\nBrug q til at slutte\n", operator);
      continue;
    } else {
      printf("result so far is  %lf\n", akkumulatoren);
    }
  }
  printf("final result is %lf\n", akkumulatoren);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x19(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <scan_data@plt>
movsbl -0x19(%rbp),%eax
cmp    $0x71,%eax
jne    117c <main+0x4c>
jmp    11c9 <main+0x99>
mov    -0x19(%rbp),%al
movsd  -0x18(%rbp),%xmm0
lea    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <do_next_op@plt>
cmp    $0x0,%rax
je     11b1 <main+0x81>
movsbl -0x19(%rbp),%esi
lea    0xef3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    115d <main+0x2d>
movsd  -0x10(%rbp),%xmm0
lea    0xf12(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
jmp    115d <main+0x2d>
movsd  -0x10(%rbp),%xmm0
lea    0xf11(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xefd(%rip),%rdi
call   1030 <puts@plt>
lea    0xf(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1060 <scan_data@plt>
mov    0xf(%rsp),%al
xorps  %xmm0,%xmm0
cmp    $0x71,%al
je     1201 <main+0xc1>
lea    0x18(%rsp),%r15
lea    0xea6(%rip),%r14
lea    0xf(%rsp),%r12
lea    0x10(%rsp),%rbx
lea    0xe5e(%rip),%r13
jmp    11d3 <main+0x93>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0xf(%rsp),%esi
mov    %r13,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scan_data@plt>
movzbl 0xf(%rsp),%eax
cmp    $0x71,%al
je     11fb <main+0xbb>
movsd  0x10(%rsp),%xmm0
movsbl %al,%edi
mov    %r15,%rsi
call   1050 <do_next_op@plt>
test   %rax,%rax
jne    11b0 <main+0x70>
movsd  0x18(%rsp),%xmm0
mov    %r14,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    11bf <main+0x7f>
movsd  0x18(%rsp),%xmm0
lea    0xe46(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [152 x i8] c"En lille lommeregner.\0AHer er de gyldige operationer:\0A + addition\0A - subtraktion\0A * multiplikation\0A / division\0A ^ potensopl\C3\B8ftning\0A q quit\0A\00"
@.str.1 = [55 x i8] c"Kan ikke forst\C3\A5 operatoren '%c'\0ABrug q til at slutte\0A\00"
@.str.2 = [23 x i8] c"result so far is %lf\0A\00"
@.str.3 = [21 x i8] c"final result is %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca i8
store i32 0, i32* %1
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %0, %17, %24
%7 = call i32 @scan_data(i8* %4, double* %3)
%8 = load i8, i8* %4
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 113
br i1 %10, label %11, label %12
11: ; preds = %6
br label %25
12: ; preds = %6
%13 = load i8, i8* %4
%14 = load double, double* %3
%15 = call i64 @do_next_op(i8 signext %13, double %14, double* %2)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %6
21: ; preds = %12
%22 = load double, double* %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %22)
br label %24
24: ; preds = %21
br label %6
25: ; preds = %11
%26 = load double, double* %2
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), double %26)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [55 x i8] c"Kan ikke forst\C3\A5 operatoren '%c'\0ABrug q til at slutte\0A\00"
@.str.2 = [23 x i8] c"result so far is %lf\0A\00"
@.str.3 = [21 x i8] c"final result is %lf\0A\00"
@str = [151 x i8] c"En lille lommeregner.\0AHer er de gyldige operationer:\0A + addition\0A - subtraktion\0A * multiplikation\0A / division\0A ^ potensopl\C3\B8ftning\0A q quit\00"
define i32 @main() {
%1 = alloca double
%2 = alloca double
%3 = alloca i8
%4 = bitcast double* %1 to i8*
store double 0.000000e+00, double* %1
%5 = bitcast double* %2 to i8*
store double 0.000000e+00, double* %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([151 x i8], [151 x i8]* @str, i64 0, i64 0))
%7 = call i32 @scan_data(i8* %3, double* %2)
%8 = load i8, i8* %3
%9 = icmp eq i8 %8, 113
br i1 %9, label %28, label %10
10: ; preds = %0, %19
%11 = phi i8 [ %21, %19 ], [ %8, %0 ]
%12 = load double, double* %2
%13 = call i64 @do_next_op(i8 signext %11, double %12, double* %1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %10
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %23
%20 = call i32 @scan_data(i8* %3, double* %2)
%21 = load i8, i8* %3
%22 = icmp eq i8 %21, 113
br i1 %22, label %26, label %10
23: ; preds = %10
%24 = load double, double* %1
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), double %24)
br label %19
26: ; preds = %19
%27 = load double, double* %1
br label %28
28: ; preds = %26, %0
%29 = phi double [ %27, %26 ], [ 0.000000e+00, %0 ]
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), double %29)
ret i32 0
}