#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*/ fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int *, int, int, int /*<<< orphan*/ *);
int get_telemetry_sequence(void) {
  int seq = 0;
  FILE *fileds = fopen("/tmp/aprsTemperSequence", "rb");
  if (fileds) {
    fread(&seq, sizeof(int), 1, fileds);
    fclose(fileds);
  }
  seq++;
  if (seq > 999)
    seq = 1;
  fileds = fopen("/tmp/aprsTemperSequence", "wb");
  if (fileds) {
    fwrite(&seq, sizeof(int), 1, fileds);
    fclose(fileds);
  }
  return seq;
}


x86 assembly (clang, -O0):
<get_telemetry_sequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    0xebb(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1191 <get_telemetry_sequence+0x51>
mov    -0x10(%rbp),%rcx
lea    -0x4(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x3e7,-0x4(%rbp)
jle    11ae <get_telemetry_sequence+0x6e>
movl   $0x1,-0x4(%rbp)
lea    0xe4b(%rip),%rdi
lea    0xe5f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f0 <get_telemetry_sequence+0xb0>
mov    -0x10(%rbp),%rcx
lea    -0x4(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1060 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_telemetry_sequence>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xea9(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a0 <get_telemetry_sequence+0x60>
mov    %rax,%rbx
lea    0xc(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0xc(%rsp),%eax
lea    0x1(%rax),%ebx
cmp    $0x3e7,%eax
cmovge %ebp,%ebx
jmp    11a5 <get_telemetry_sequence+0x65>
mov    $0x1,%ebx
mov    %ebx,0xc(%rsp)
lea    0xe50(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11e7 <get_telemetry_sequence+0xa7>
mov    %rax,%r14
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"/tmp/aprsTemperSequence\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
define i32 @get_telemetry_sequence() {
%1 = alloca i32
%2 = alloca i32*
store i32 0, i32* %1
%3 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %2
%4 = load i32*, i32** %2
%5 = icmp ne i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32*, i32** %2
%8 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %7)
%9 = load i32*, i32** %2
%10 = call i32 @fclose(i32* %9)
br label %11
11: ; preds = %6, %0
%12 = load i32, i32* %1
%13 = add nsw i32 %12, 1
store i32 %13, i32* %1
%14 = load i32, i32* %1
%15 = icmp sgt i32 %14, 999
br i1 %15, label %16, label %17
16: ; preds = %11
store i32 1, i32* %1
br label %17
17: ; preds = %16, %11
%18 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %2
%19 = load i32*, i32** %2
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = load i32*, i32** %2
%23 = call i32 @fwrite(i32* %1, i32 4, i32 1, i32* %22)
%24 = load i32*, i32** %2
%25 = call i32 @fclose(i32* %24)
br label %26
26: ; preds = %21, %17
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [24 x i8] c"/tmp/aprsTemperSequence\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c"wb\00"
define i32 @get_telemetry_sequence() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = call i32 @fread(i32* %1, i32 4, i32 1, i32* %3)
%7 = tail call i32 @fclose(i32* %3)
%8 = load i32, i32* %1
%9 = add nsw i32 %8, 1
%10 = icmp sgt i32 %8, 998
%11 = select i1 %10, i32 1, i32 %9
br label %12
12: ; preds = %5, %0
%13 = phi i32 [ 1, %0 ], [ %11, %5 ]
store i32 %13, i32* %1
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = call i32 @fwrite(i32* %1, i32 4, i32 1, i32* %14)
%18 = tail call i32 @fclose(i32* %14)
%19 = load i32, i32* %1
br label %20
20: ; preds = %16, %12
%21 = phi i32 [ %19, %16 ], [ %13, %12 ]
ret i32 %21
}