#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*/ MP_motor(int, int);
char getchar();
int /*<<< orphan*/ printf(char *, ...);
void MP_switch_motor(void) {
  int PV_motor = 0, PV_command = 0;
  char PV_char;
  printf("Ausgaenge (Motoren) schalten 0..3:\n");
  PV_char = getchar();
  PV_motor = (int)PV_char - (int)'0';
  printf(
      "\nSchaltwert fuer die beiden Ausgaenge (Eingaenge des Motors) 0..3:\n");
  PV_char = getchar();
  printf("\n");
  PV_command = (int)PV_char - (int)'0';
  printf("Motor %d, Kommando %d\n", PV_motor, PV_command);
  switch (PV_motor) {
  case 0:
    MP_motor(0, PV_command);
    break;
  case 1:
    MP_motor(1, PV_command);
    break;
  case 2:
    MP_motor(2, PV_command);
    break;
  case 3:
    MP_motor(3, PV_command);
    break;
  default:
    printf("Falsche Eingabe - Motor %d gibt es nicht\n", PV_motor);
  };
}


x86 assembly (clang, -O0):
<MP_switch_motor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x19(%rbp)
call   1030 <printf@plt>
mov    -0x19(%rbp),%al
call   1040 <getchar@plt>
mov    %al,%cl
mov    -0x19(%rbp),%al
mov    %cl,-0x9(%rbp)
movsbl -0x9(%rbp),%ecx
add    $0xffffffd0,%ecx
mov    %ecx,-0x4(%rbp)
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
mov    -0x19(%rbp),%al
call   1040 <getchar@plt>
mov    %al,%cl
mov    -0x19(%rbp),%al
mov    %cl,-0x9(%rbp)
lea    0xee2(%rip),%rdi
call   1030 <printf@plt>
mov    -0x19(%rbp),%al
movsbl -0x9(%rbp),%ecx
add    $0xffffffd0,%ecx
mov    %ecx,-0x8(%rbp)
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xec5(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x3,%rax
ja     1222 <MP_switch_motor+0xf2>
mov    -0x18(%rbp),%rax
lea    0xe2c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%esi
xor    %edi,%edi
call   1050 <MP_motor@plt>
jmp    1233 <MP_switch_motor+0x103>
mov    -0x8(%rbp),%esi
mov    $0x1,%edi
call   1050 <MP_motor@plt>
jmp    1233 <MP_switch_motor+0x103>
mov    -0x8(%rbp),%esi
mov    $0x2,%edi
call   1050 <MP_motor@plt>
jmp    1233 <MP_switch_motor+0x103>
mov    -0x8(%rbp),%esi
mov    $0x3,%edi
call   1050 <MP_motor@plt>
jmp    1233 <MP_switch_motor+0x103>
mov    -0x4(%rbp),%esi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MP_switch_motor>:
push   %rbp
push   %rbx
push   %rax
lea    0xef7(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
movsbl %al,%ebx
add    $0xffffffd0,%ebx
lea    0xf01(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    %eax,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
movsbl %bpl,%ebp
add    $0xffffffd0,%ebp
lea    0xe77(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x3,%ebx
ja     11bd <MP_switch_motor+0x6d>
lea    0xe50(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %edi,%edi
jmp    11e6 <MP_switch_motor+0x96>
lea    0xe63(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <printf@plt>
mov    $0x1,%edi
jmp    11e6 <MP_switch_motor+0x96>
mov    $0x2,%edi
jmp    11e6 <MP_switch_motor+0x96>
mov    $0x3,%edi
mov    %ebp,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <MP_motor@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Ausgaenge (Motoren) schalten 0..3:\0A\00"
@.str.1 = [68 x i8] c"\0ASchaltwert fuer die beiden Ausgaenge (Eingaenge des Motors) 0..3:\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [23 x i8] c"Motor %d, Kommando %d\0A\00"
@.str.4 = [42 x i8] c"Falsche Eingabe - Motor %d gibt es nicht\0A\00"
define void @MP_switch_motor() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%5 = call signext i8 (...) @getchar()
store i8 %5, i8* %3
%6 = load i8, i8* %3
%7 = sext i8 %6 to i32
%8 = sub nsw i32 %7, 48
store i32 %8, i32* %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%10 = call signext i8 (...) @getchar()
store i8 %10, i8* %3
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = sub nsw i32 %13, 48
store i32 %14, i32* %2
%15 = load i32, i32* %1
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %15, i32 %16)
%18 = load i32, i32* %1
switch i32 %18, label %31 [
i32 0, label %19
i32 1, label %22
i32 2, label %25
i32 3, label %28
]
19: ; preds = %0
%20 = load i32, i32* %2
%21 = call i32 @MP_motor(i32 0, i32 %20)
br label %34
22: ; preds = %0
%23 = load i32, i32* %2
%24 = call i32 @MP_motor(i32 1, i32 %23)
br label %34
25: ; preds = %0
%26 = load i32, i32* %2
%27 = call i32 @MP_motor(i32 2, i32 %26)
br label %34
28: ; preds = %0
%29 = load i32, i32* %2
%30 = call i32 @MP_motor(i32 3, i32 %29)
br label %34
31: ; preds = %0
%32 = load i32, i32* %1
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %28, %25, %22, %19
ret void
}

LLVM IR (-O2):
@.str.3 = [23 x i8] c"Motor %d, Kommando %d\0A\00"
@.str.4 = [42 x i8] c"Falsche Eingabe - Motor %d gibt es nicht\0A\00"
@str = [35 x i8] c"Ausgaenge (Motoren) schalten 0..3:\00"
@str.5 = [67 x i8] c"\0ASchaltwert fuer die beiden Ausgaenge (Eingaenge des Motors) 0..3:\00"
define void @MP_switch_motor() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%2 = tail call signext i8 (...) @getchar()
%3 = sext i8 %2 to i32
%4 = add nsw i32 %3, -48
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.5, i64 0, i64 0))
%6 = tail call signext i8 (...) @getchar()
%7 = tail call i32 @putchar(i32 10)
%8 = sext i8 %6 to i32
%9 = add nsw i32 %8, -48
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %4, i32 %9)
switch i32 %3, label %19 [
i32 48, label %11
i32 49, label %13
i32 50, label %15
i32 51, label %17
]
11: ; preds = %0
%12 = tail call i32 @MP_motor(i32 0, i32 %9)
br label %21
13: ; preds = %0
%14 = tail call i32 @MP_motor(i32 1, i32 %9)
br label %21
15: ; preds = %0
%16 = tail call i32 @MP_motor(i32 2, i32 %9)
br label %21
17: ; preds = %0
%18 = tail call i32 @MP_motor(i32 3, i32 %9)
br label %21
19: ; preds = %0
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i32 %4)
br label %21
21: ; preds = %19, %17, %15, %13, %11
ret void
}