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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ strcmp(char *, char *);
int getAim() {
  FILE *in;
  in = fopen("/var/run/lock/rotor."
             "aim",
             "r");
  if (!in) {
    return -1;
  }
  char buff[1024];
  if (!fgets(buff, sizeof(buff), in)) {
    fclose(in);
    return -1;
  }
  fclose(in);
  if (strcmp(buff, "stop") == 0) {
    return -1;
  }
  for (int i = 0; i < sizeof(buff); i++) {
    if (buff[i] == 0 || buff[i] == '\r' || buff[i] == '\n') {
      buff[i] = 0;
      return atoi(buff);
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<getAim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
lea    0xe9e(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1189 <getAim+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <getAim+0x146>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    11bc <getAim+0x6c>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <getAim+0x146>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x410(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11ee <getAim+0x9e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1296 <getAim+0x146>
movl   $0x0,-0x414(%rbp)
movslq -0x414(%rbp),%rax
cmp    $0x400,%rax
jae    128f <getAim+0x13f>
movslq -0x414(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
je     1253 <getAim+0x103>
movslq -0x414(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xd,%eax
je     1253 <getAim+0x103>
movslq -0x414(%rbp),%rax
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1276 <getAim+0x126>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4(%rbp)
jmp    1296 <getAim+0x146>
jmp    127b <getAim+0x12b>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    11f8 <getAim+0xa8>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getAim>:
push   %rbp
push   %rbx
sub    $0x408,%rsp
lea    0xea0(%rip),%rdi
lea    0xeb1(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1262 <getAim+0x112>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    $0xffffffff,%ebx
test   %ebp,%ebp
je     12a1 <getAim+0x151>
lea    0xe74(%rip),%rsi
mov    %rsp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     12a1 <getAim+0x151>
mov    $0x7,%eax
mov    $0x2401,%ecx
movzbl -0x7(%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     11d6 <getAim+0x86>
bt     %rdx,%rcx
jb     1269 <getAim+0x119>
movzbl -0x6(%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     11eb <getAim+0x9b>
bt     %rdx,%rcx
jb     126f <getAim+0x11f>
movzbl -0x5(%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     11fc <getAim+0xac>
bt     %rdx,%rcx
jb     1275 <getAim+0x125>
movzbl -0x4(%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     120d <getAim+0xbd>
bt     %rdx,%rcx
jb     127b <getAim+0x12b>
movzbl -0x3(%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     121e <getAim+0xce>
bt     %rdx,%rcx
jb     1281 <getAim+0x131>
movzbl -0x2(%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     122f <getAim+0xdf>
bt     %rdx,%rcx
jb     1287 <getAim+0x137>
movzbl -0x1(%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     1240 <getAim+0xf0>
bt     %rdx,%rcx
jb     128d <getAim+0x13d>
movzbl (%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     1250 <getAim+0x100>
bt     %rdx,%rcx
jb     1291 <getAim+0x141>
add    $0x8,%rax
cmp    $0x407,%rax
jne    11c1 <getAim+0x71>
jmp    12a1 <getAim+0x151>
mov    $0xffffffff,%ebx
jmp    12a1 <getAim+0x151>
add    $0xfffffffffffffff9,%rax
jmp    1291 <getAim+0x141>
add    $0xfffffffffffffffa,%rax
jmp    1291 <getAim+0x141>
add    $0xfffffffffffffffb,%rax
jmp    1291 <getAim+0x141>
add    $0xfffffffffffffffc,%rax
jmp    1291 <getAim+0x141>
add    $0xfffffffffffffffd,%rax
jmp    1291 <getAim+0x141>
add    $0xfffffffffffffffe,%rax
jmp    1291 <getAim+0x141>
add    $0xffffffffffffffff,%rax
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x408,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/var/run/lock/rotor.aim\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"stop\00"
define i32 @getAim() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %0
store i32 -1, i32* %1
br label %61
9: ; preds = %0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = load i32*, i32** %2
%12 = call i32 @fgets(i8* %10, i32 1024, i32* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = load i32*, i32** %2
%16 = call i32 @fclose(i32* %15)
store i32 -1, i32* %1
br label %61
17: ; preds = %9
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 -1, i32* %1
br label %61
24: ; preds = %17
store i32 0, i32* %4
br label %25
25: ; preds = %57, %24
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = icmp ult i64 %27, 1024
br i1 %28, label %29, label %60
29: ; preds = %25
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %50, label %36
36: ; preds = %29
%37 = load i32, i32* %4
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 13
br i1 %42, label %50, label %43
43: ; preds = %36
%44 = load i32, i32* %4
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %45
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 10
br i1 %49, label %50, label %56
50: ; preds = %43, %36, %29
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %52
store i8 0, i8* %53
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%55 = call i32 @atoi(i8* %54)
store i32 %55, i32* %1
br label %61
56: ; preds = %43
br label %57
57: ; preds = %56
%58 = load i32, i32* %4
%59 = add nsw i32 %58, 1
store i32 %59, i32* %4
br label %25
60: ; preds = %25
store i32 -1, i32* %1
br label %61
61: ; preds = %60, %50, %23, %14, %8
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@.str = [24 x i8] c"/var/run/lock/rotor.aim\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [5 x i8] c"stop\00"
define i32 @getAim() {
%1 = alloca [1024 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %54, label %4
4: ; preds = %0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%6 = call i32 @fgets(i8* %5, i32 1024, i32* %2)
%7 = icmp eq i32 %6, 0
%8 = call i32 @fclose(i32* %2)
br i1 %7, label %52, label %9
9: ; preds = %4
%10 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %52, label %12
12: ; preds = %9, %49
%13 = phi i64 [ %50, %49 ], [ 0, %9 ]
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %21 [
i8 0, label %16
i8 13, label %16
i8 10, label %16
]
16: ; preds = %45, %45, %45, %41, %41, %41, %37, %37, %37, %33, %33, %33, %29, %29, %29, %25, %25, %25, %21, %21, %21, %12, %12, %12
%17 = phi i64 [ %13, %12 ], [ %13, %12 ], [ %13, %12 ], [ %22, %21 ], [ %22, %21 ], [ %22, %21 ], [ %26, %25 ], [ %26, %25 ], [ %26, %25 ], [ %30, %29 ], [ %30, %29 ], [ %30, %29 ], [ %34, %33 ], [ %34, %33 ], [ %34, %33 ], [ %38, %37 ], [ %38, %37 ], [ %38, %37 ], [ %42, %41 ], [ %42, %41 ], [ %42, %41 ], [ %46, %45 ], [ %46, %45 ], [ %46, %45 ]
%18 = and i64 %17, 4294967295
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @atoi(i8* %5)
br label %52
21: ; preds = %12
%22 = or i64 %13, 1
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %22
%24 = load i8, i8* %23
switch i8 %24, label %25 [
i8 0, label %16
i8 13, label %16
i8 10, label %16
]
25: ; preds = %21
%26 = or i64 %13, 2
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %26
%28 = load i8, i8* %27
switch i8 %28, label %29 [
i8 0, label %16
i8 13, label %16
i8 10, label %16
]
29: ; preds = %25
%30 = or i64 %13, 3
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %30
%32 = load i8, i8* %31
switch i8 %32, label %33 [
i8 0, label %16
i8 13, label %16
i8 10, label %16
]
33: ; preds = %29
%34 = or i64 %13, 4
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %34
%36 = load i8, i8* %35
switch i8 %36, label %37 [
i8 0, label %16
i8 13, label %16
i8 10, label %16
]
37: ; preds = %33
%38 = or i64 %13, 5
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %38
%40 = load i8, i8* %39
switch i8 %40, label %41 [
i8 0, label %16
i8 13, label %16
i8 10, label %16
]
41: ; preds = %37
%42 = or i64 %13, 6
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %42
%44 = load i8, i8* %43
switch i8 %44, label %45 [
i8 0, label %16
i8 13, label %16
i8 10, label %16
]
45: ; preds = %41
%46 = or i64 %13, 7
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %46
%48 = load i8, i8* %47
switch i8 %48, label %49 [
i8 0, label %16
i8 13, label %16
i8 10, label %16
]
49: ; preds = %45
%50 = add nuw nsw i64 %13, 8
%51 = icmp eq i64 %50, 1024
br i1 %51, label %52, label %12
52: ; preds = %49, %4, %16, %9
%53 = phi i32 [ -1, %9 ], [ %20, %16 ], [ -1, %4 ], [ -1, %49 ]
br label %54
54: ; preds = %0, %52
%55 = phi i32 [ %53, %52 ], [ -1, %0 ]
ret i32 %55
}