#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*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/);
void changeSpeed(int i, int gpio, char *fileString) {
  FILE *file;
  for (;;) {
    file = fopen("stop.txt", "r");
    if (fgetc(file) == 's')
      break;
    fclose(file);
  }
  printf("ENDING\n");
  file = fopen("itEnded.txt", "a");
  fputs("The Function Has Ended", file);
  fclose(file);
  pthread_exit(0);
}


x86 assembly (clang, -O0):
<changeSpeed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
movsbl %al,%eax
cmp    $0x73,%eax
jne    11a3 <changeSpeed+0x43>
jmp    11b1 <changeSpeed+0x51>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1172 <changeSpeed+0x12>
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
lea    0xe4f(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1070 <pthread_exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<changeSpeed>:
push   %r15
push   %r14
push   %rbx
lea    0xe94(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
cmp    $0x73,%al
je     11c2 <changeSpeed+0x62>
lea    0xe72(%rip),%r14
lea    0xe74(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
cmp    $0x73,%al
jne    11a0 <changeSpeed+0x40>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
lea    0xe36(%rip),%rdi
lea    0xe3b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe2e(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <pthread_exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"stop.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"ENDING\0A\00"
@.str.3 = [12 x i8] c"itEnded.txt\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [23 x i8] c"The Function Has Ended\00"
define void @changeSpeed(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
br label %8
8: ; preds = %15, %3
%9 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i32*, i32** %7
%11 = call signext i8 @fgetc(i32* %10)
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 115
br i1 %13, label %14, label %15
14: ; preds = %8
br label %18
15: ; preds = %8
%16 = load i32*, i32** %7
%17 = call i32 @fclose(i32* %16)
br label %8
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = call i32 @fputs(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32* %21)
%23 = load i32*, i32** %7
%24 = call i32 @fclose(i32* %23)
%25 = call i32 @pthread_exit(i32 0)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"stop.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [12 x i8] c"itEnded.txt\00"
@.str.4 = [2 x i8] c"a\00"
@.str.5 = [23 x i8] c"The Function Has Ended\00"
@str = [7 x i8] c"ENDING\00"
define void @changeSpeed(i32 %0, i32 %1, i8* nocapture readnone %2) {
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call signext i8 @fgetc(i32* %4)
%6 = icmp eq i8 %5, 115
br i1 %6, label %13, label %7
7: ; preds = %3, %7
%8 = phi i32* [ %10, %7 ], [ %4, %3 ]
%9 = tail call i32 @fclose(i32* %8)
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call signext i8 @fgetc(i32* %10)
%12 = icmp eq i8 %11, 115
br i1 %12, label %13, label %7
13: ; preds = %7, %3
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%16 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 22, i64 1, i32* %15)
%17 = tail call i32 @fclose(i32* %15)
%18 = tail call i32 @pthread_exit(i32 0)
ret void
}