#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 */
float calc_power_i(float, float);
float calc_power_r(float, float);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, float *);
int /*<<< orphan*/ stdin;
int strcmp(char *, char *);
int /*<<< orphan*/ strtol(char *, char **, int);
int main(void) {
  float volt, current, resistance, effekt;
  char *val;
  char *pointer_m = "m";
  char *pointer_s = "s";
  char input[3];
  printf("Ange spänning: ");
  scanf("%f", &volt);
  printf("Du angav %.2f V \n", volt);
  printf("Välj motstånd eller ström (m/s): ");
  do {
    fgets(input, sizeof input, stdin);
    strtol(input, &val, 10);
  } while (strcmp(pointer_s, val) == 1 && strcmp(pointer_m, val) == 1);
  if (strcmp(pointer_m, val) == -1 && strcmp(pointer_s, val) == 1) {
    printf("Ange motstånd: ");
    scanf("%f", &resistance);
    printf("Du angav %.2f Ohm\n", resistance);
    effekt = calc_power_r(volt, resistance);
    printf("Effekten är: %f Watt\n", effekt);
  } else {
    printf("Ange ström: ");
    scanf("%f", &current);
    printf("Du angav %.2f A \n", current);
    effekt = calc_power_i(volt, current);
    printf("Effekten är: %f Watt\n", effekt);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xe71(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6b(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <scanf@plt>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe55(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x33(%rbp),%rdi
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
mov    $0x3,%esi
call   1050 <fgets@plt>
lea    -0x33(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x1,%ecx
mov    %al,-0x34(%rbp)
jne    1234 <main+0xc4>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x1,%eax
sete   %al
mov    %al,-0x34(%rbp)
mov    -0x34(%rbp),%al
test   $0x1,%al
jne    11d8 <main+0x68>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0xffffffff,%eax
jne    12d0 <main+0x160>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x1,%eax
jne    12d0 <main+0x160>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd95(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1080 <scanf@plt>
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdc7(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x8(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
call   1030 <calc_power_r@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdaf(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
jmp    1330 <main+0x1c0>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xd30(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1080 <scanf@plt>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd9a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  -0x8(%rbp),%xmm0
movss  -0xc(%rbp),%xmm1
call   1090 <calc_power_i@plt>
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd4a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe82(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1080 <scanf@plt>
movss  0x8(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe6a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe6e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e1e(%rip),%rbp
lea    0xd(%rsp),%r13
lea    0x10(%rsp),%r14
lea    0xe27(%rip),%r15
lea    0xe1e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%rbp),%edx
mov    %r13,%rdi
mov    $0x3,%esi
call   1050 <fgets@plt>
mov    %r13,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    0x10(%rsp),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
cmp    $0x1,%eax
jne    1284 <main+0x114>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <strcmp@plt>
cmp    $0x1,%eax
je     11f0 <main+0x80>
cmp    $0xffffffff,%eax
jne    1284 <main+0x114>
lea    0xe0e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdc6(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdf6(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x8(%rsp),%xmm0
movss  0x4(%rsp),%xmm1
call   1030 <calc_power_r@plt>
jmp    12cc <main+0x15c>
lea    0xdff(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd7c(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
movss  0x4(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xde4(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movss  0x8(%rsp),%xmm0
movss  0x4(%rsp),%xmm1
call   1090 <calc_power_i@plt>
cvtss2sd %xmm0,%xmm0
lea    0xd9c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"m\00"
@.str.1 = [2 x i8] c"s\00"
@.str.2 = [17 x i8] c"Ange sp\C3\A4nning: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [18 x i8] c"Du angav %.2f V \0A\00"
@.str.5 = [37 x i8] c"V\C3\A4lj motst\C3\A5nd eller str\C3\B6m (m/s): \00"
@stdin = global i32 0
@.str.6 = [17 x i8] c"Ange motst\C3\A5nd: \00"
@.str.7 = [19 x i8] c"Du angav %.2f Ohm\0A\00"
@.str.8 = [23 x i8] c"Effekten \C3\A4r: %f Watt\0A\00"
@.str.9 = [14 x i8] c"Ange str\C3\B6m: \00"
@.str.10 = [18 x i8] c"Du angav %.2f A \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [3 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %2)
%12 = load float, float* %2
%13 = fpext float %12 to double
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), double %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %16
16: ; preds = %32, %0
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 3, i32 %18)
%20 = getelementptr inbounds [3 x i8], [3 x i8]* %9, i64 0, i64 0
%21 = call i32 @strtol(i8* %20, i8** %6, i32 10)
br label %22
22: ; preds = %16
%23 = load i8*, i8** %8
%24 = load i8*, i8** %6
%25 = call i32 @strcmp(i8* %23, i8* %24)
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = load i8*, i8** %6
%30 = call i32 @strcmp(i8* %28, i8* %29)
%31 = icmp eq i32 %30, 1
br label %32
32: ; preds = %27, %22
%33 = phi i1 [ false, %22 ], [ %31, %27 ]
br i1 %33, label %16, label %34
34: ; preds = %32
%35 = load i8*, i8** %7
%36 = load i8*, i8** %6
%37 = call i32 @strcmp(i8* %35, i8* %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %56
39: ; preds = %34
%40 = load i8*, i8** %8
%41 = load i8*, i8** %6
%42 = call i32 @strcmp(i8* %40, i8* %41)
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %56
44: ; preds = %39
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %4)
%47 = load float, float* %4
%48 = fpext float %47 to double
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), double %48)
%50 = load float, float* %2
%51 = load float, float* %4
%52 = call float @calc_power_r(float %50, float %51)
store float %52, float* %5
%53 = load float, float* %5
%54 = fpext float %53 to double
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), double %54)
br label %68
56: ; preds = %39, %34
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%58 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %3)
%59 = load float, float* %3
%60 = fpext float %59 to double
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), double %60)
%62 = load float, float* %2
%63 = load float, float* %3
%64 = call float @calc_power_i(float %62, float %63)
store float %64, float* %5
%65 = load float, float* %5
%66 = fpext float %65 to double
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), double %66)
br label %68
68: ; preds = %56, %44
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"m\00"
@.str.1 = [2 x i8] c"s\00"
@.str.2 = [17 x i8] c"Ange sp\C3\A4nning: \00"
@.str.3 = [3 x i8] c"%f\00"
@.str.4 = [18 x i8] c"Du angav %.2f V \0A\00"
@.str.5 = [37 x i8] c"V\C3\A4lj motst\C3\A5nd eller str\C3\B6m (m/s): \00"
@stdin = global i32 0
@.str.6 = [17 x i8] c"Ange motst\C3\A5nd: \00"
@.str.7 = [19 x i8] c"Du angav %.2f Ohm\0A\00"
@.str.8 = [23 x i8] c"Effekten \C3\A4r: %f Watt\0A\00"
@.str.9 = [14 x i8] c"Ange str\C3\B6m: \00"
@.str.10 = [18 x i8] c"Du angav %.2f A \0A\00"
define i32 @main() {
%1 = alloca float
%2 = alloca float
%3 = alloca float
%4 = alloca i8*
%5 = alloca [3 x i8]
%6 = bitcast float* %1 to i8*
%7 = bitcast float* %2 to i8*
%8 = bitcast float* %3 to i8*
%9 = bitcast i8** %4 to i8*
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %1)
%13 = load float, float* %1
%14 = fpext float %13 to double
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), double %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
br label %17
17: ; preds = %24, %0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %10, i32 3, i32 %18)
%20 = call i32 @strtol(i8* %10, i8** %4, i32 10)
%21 = load i8*, i8** %4
%22 = call i32 @strcmp(i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* dereferenceable(1) %21)
%23 = icmp eq i32 %22, 1
br i1 %23, label %24, label %35
24: ; preds = %17
%25 = call i32 @strcmp(i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* dereferenceable(1) %21)
switch i32 %25, label %35 [
i32 1, label %17
i32 -1, label %26
]
26: ; preds = %24
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %3)
%29 = load float, float* %3
%30 = fpext float %29 to double
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0), double %30)
%32 = load float, float* %1
%33 = load float, float* %3
%34 = call float @calc_power_r(float %32, float %33)
br label %44
35: ; preds = %17, %24
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%37 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), float* %2)
%38 = load float, float* %2
%39 = fpext float %38 to double
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), double %39)
%41 = load float, float* %1
%42 = load float, float* %2
%43 = call float @calc_power_i(float %41, float %42)
br label %44
44: ; preds = %35, %26
%45 = phi float [ %43, %35 ], [ %34, %26 ]
%46 = fpext float %45 to double
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), double %46)
ret i32 0
}