#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ motor_drive(char *, char *);
int /*<<< orphan*/ printf(char *);
void reset_counters_and_motors(void) {
  FILE *count_l, *count_r;
  motor_drive("0", "0");
  printf("Reset counter\n");
  if ((count_l = fopen("/dev/rtcounter_l0", "w")) != NULL &&
      (count_r = fopen("/dev/rtcounter_r0", "w")) != NULL) {
    fputs("0", count_l);
    fputs("0", count_r);
  }
  fclose(count_l);
  fclose(count_r);
}


x86 assembly (clang, -O0):
<reset_counters_and_motors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec0(%rip),%rsi
mov    %rsi,%rdi
call   1060 <motor_drive@plt>
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
lea    0xe95(%rip),%rdi
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11d5 <reset_counters_and_motors+0x85>
lea    0xe88(%rip),%rdi
lea    0xe7f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11d5 <reset_counters_and_motors+0x85>
mov    -0x8(%rbp),%rsi
lea    0xe5f(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x10(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reset_counters_and_motors>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
mov    %rdi,%rsi
call   1050 <motor_drive@plt>
lea    0xebc(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8a(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     11c1 <reset_counters_and_motors+0x71>
lea    0xe83(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c3 <reset_counters_and_motors+0x73>
mov    %rax,%rbx
mov    $0x30,%edi
mov    %r14,%rsi
call   1060 <fputc@plt>
mov    $0x30,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
jmp    11c5 <reset_counters_and_motors+0x75>
jmp    11c5 <reset_counters_and_motors+0x75>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
@.str.1 = [15 x i8] c"Reset counter\0A\00"
@.str.2 = [18 x i8] c"/dev/rtcounter_l0\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [18 x i8] c"/dev/rtcounter_r0\00"
define void @reset_counters_and_motors() {
%1 = alloca i32*
%2 = alloca i32*
%3 = call i32 @motor_drive(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %5, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %15
7: ; preds = %0
%8 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %8, i32** %2
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = load i32*, i32** %1
%12 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* %11)
%13 = load i32*, i32** %2
%14 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* %13)
br label %15
15: ; preds = %10, %7, %0
%16 = load i32*, i32** %1
%17 = call i32 @fclose(i32* %16)
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
@.str.2 = [18 x i8] c"/dev/rtcounter_l0\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [18 x i8] c"/dev/rtcounter_r0\00"
@str = [14 x i8] c"Reset counter\00"
define void @reset_counters_and_motors() {
%1 = tail call i32 @motor_drive(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %11, label %5
5: ; preds = %0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = tail call i32 @fputc(i32 48, i32* %3)
%10 = tail call i32 @fputc(i32 48, i32* %6)
br label %11
11: ; preds = %8, %5, %0
%12 = phi i32* [ %6, %8 ], [ null, %5 ], [ undef, %0 ]
%13 = tail call i32 @fclose(i32* %3)
%14 = tail call i32 @fclose(i32* %12)
ret void
}