#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ motor_drive(char *, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ print_counter(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ reset_counters_and_motors();
int /*<<< orphan*/ usleep(int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int motoren = open("/dev/rtmotoren0", O_WRONLY);
  printf("Motor On\n");
  write(motoren, "1", 1);
  printf("Rotate left motor\n");
  usleep(500 * 1000);
  motor_drive("400", "0");
  print_counter(2);
  reset_counters_and_motors();
  printf("Rotate right motor\n");
  usleep(500 * 1000);
  motor_drive("0", "400");
  print_counter(2);
  reset_counters_and_motors();
  printf("Move forward\n");
  usleep(500 * 1000);
  motor_drive("400", "400");
  print_counter(2);
  reset_counters_and_motors();
  printf("Move backward\n");
  usleep(500 * 1000);
  motor_drive("-400", "-400");
  print_counter(2);
  reset_counters_and_motors();
  printf("Motor Off\n");
  write(motoren, "0", 1);
  close(motoren);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xe5d(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
lea    0xe7d(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1050 <motor_drive@plt>
mov    $0x2,%edi
call   1070 <print_counter@plt>
mov    $0x0,%al
call   1090 <reset_counters_and_motors@plt>
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
lea    0xe45(%rip),%rdi
lea    0xe3c(%rip),%rsi
call   1050 <motor_drive@plt>
mov    $0x2,%edi
call   1070 <print_counter@plt>
mov    $0x0,%al
call   1090 <reset_counters_and_motors@plt>
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
lea    0xe09(%rip),%rsi
mov    %rsi,%rdi
call   1050 <motor_drive@plt>
mov    $0x2,%edi
call   1070 <print_counter@plt>
mov    $0x0,%al
call   1090 <reset_counters_and_motors@plt>
lea    0xdd9(%rip),%rdi
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
lea    0xdd2(%rip),%rsi
mov    %rsi,%rdi
call   1050 <motor_drive@plt>
mov    $0x2,%edi
call   1070 <print_counter@plt>
mov    $0x0,%al
call   1090 <reset_counters_and_motors@plt>
lea    0xdb7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    0xda6(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
lea    0xe6c(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
lea    0xe75(%rip),%rdi
call   1030 <puts@plt>
lea    0xe62(%rip),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1040 <write@plt>
lea    0xe5f(%rip),%rdi
call   1030 <puts@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
lea    0xe3c(%rip),%rbx
lea    0xe37(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <motor_drive@plt>
mov    $0x2,%edi
call   1070 <print_counter@plt>
xor    %eax,%eax
call   1090 <reset_counters_and_motors@plt>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <motor_drive@plt>
mov    $0x2,%edi
call   1070 <print_counter@plt>
xor    %eax,%eax
call   1090 <reset_counters_and_motors@plt>
lea    0xe12(%rip),%rdi
call   1030 <puts@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1050 <motor_drive@plt>
mov    $0x2,%edi
call   1070 <print_counter@plt>
xor    %eax,%eax
call   1090 <reset_counters_and_motors@plt>
lea    0xded(%rip),%rdi
call   1030 <puts@plt>
mov    $0x7a120,%edi
call   10a0 <usleep@plt>
lea    0xd97(%rip),%rdi
mov    %rdi,%rsi
call   1050 <motor_drive@plt>
mov    $0x2,%edi
call   1070 <print_counter@plt>
xor    %eax,%eax
call   1090 <reset_counters_and_motors@plt>
lea    0xdc5(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/dev/rtmotoren0\00"
@O_WRONLY = global i32 0
@.str.1 = [10 x i8] c"Motor On\0A\00"
@.str.2 = [2 x i8] c"1\00"
@.str.3 = [19 x i8] c"Rotate left motor\0A\00"
@.str.4 = [4 x i8] c"400\00"
@.str.5 = [2 x i8] c"0\00"
@.str.6 = [20 x i8] c"Rotate right motor\0A\00"
@.str.7 = [14 x i8] c"Move forward\0A\00"
@.str.8 = [15 x i8] c"Move backward\0A\00"
@.str.9 = [5 x i8] c"-400\00"
@.str.10 = [11 x i8] c"Motor Off\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @O_WRONLY
%4 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%6 = load i32, i32* %2
%7 = call i32 @write(i32 %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%8 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%9 = call i32 @usleep(i32 500000)
%10 = call i32 @motor_drive(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 @print_counter(i32 2)
%12 = call i32 (...) @reset_counters_and_motors()
%13 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%14 = call i32 @usleep(i32 500000)
%15 = call i32 @motor_drive(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 @print_counter(i32 2)
%17 = call i32 (...) @reset_counters_and_motors()
%18 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
%19 = call i32 @usleep(i32 500000)
%20 = call i32 @motor_drive(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%21 = call i32 @print_counter(i32 2)
%22 = call i32 (...) @reset_counters_and_motors()
%23 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%24 = call i32 @usleep(i32 500000)
%25 = call i32 @motor_drive(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%26 = call i32 @print_counter(i32 2)
%27 = call i32 (...) @reset_counters_and_motors()
%28 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
%29 = load i32, i32* %2
%30 = call i32 @write(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%31 = load i32, i32* %2
%32 = call i32 @close(i32 %31)
ret i32 0
}

LLVM IR (-O2):
@.str = [16 x i8] c"/dev/rtmotoren0\00"
@O_WRONLY = global i32 0
@.str.2 = [2 x i8] c"1\00"
@.str.4 = [4 x i8] c"400\00"
@.str.5 = [2 x i8] c"0\00"
@.str.9 = [5 x i8] c"-400\00"
@str = [9 x i8] c"Motor On\00"
@str.11 = [18 x i8] c"Rotate left motor\00"
@str.12 = [19 x i8] c"Rotate right motor\00"
@str.13 = [13 x i8] c"Move forward\00"
@str.14 = [14 x i8] c"Move backward\00"
@str.15 = [10 x i8] c"Motor Off\00"
define i32 @main() {
%1 = load i32, i32* @O_WRONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.11, i64 0, i64 0))
%6 = tail call i32 @usleep(i32 500000)
%7 = tail call i32 @motor_drive(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%8 = tail call i32 @print_counter(i32 2)
%9 = tail call i32 (...) @reset_counters_and_motors()
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.12, i64 0, i64 0))
%11 = tail call i32 @usleep(i32 500000)
%12 = tail call i32 @motor_drive(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i32 @print_counter(i32 2)
%14 = tail call i32 (...) @reset_counters_and_motors()
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.13, i64 0, i64 0))
%16 = tail call i32 @usleep(i32 500000)
%17 = tail call i32 @motor_drive(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i32 @print_counter(i32 2)
%19 = tail call i32 (...) @reset_counters_and_motors()
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.14, i64 0, i64 0))
%21 = tail call i32 @usleep(i32 500000)
%22 = tail call i32 @motor_drive(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%23 = tail call i32 @print_counter(i32 2)
%24 = tail call i32 (...) @reset_counters_and_motors()
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.15, i64 0, i64 0))
%26 = tail call i32 @write(i32 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%27 = tail call i32 @close(i32 %2)
ret i32 0
}