#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*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int get_sequence(char *sequence_file) {
  FILE *f;
  int sequence;
  f = fopen(sequence_file, "r");
  if (!f) {
    sequence = 1;
  } else {
    fscanf(f, "%d", &sequence);
    fclose(f);
  }
  f = fopen(sequence_file, "w");
  if (!f)
    return 0;
  fprintf(f, "%d\n", sequence + 1);
  fclose(f);
  return sequence;
}


x86 assembly (clang, -O0):
<get_sequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1177 <get_sequence+0x37>
movl   $0x1,-0x1c(%rbp)
jmp    1194 <get_sequence+0x54>
mov    -0x18(%rbp),%rdi
lea    0xe80(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bf <get_sequence+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    11e4 <get_sequence+0xa4>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
lea    0xe37(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sequence>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1179 <get_sequence+0x39>
mov    %rax,%rbx
lea    0xea0(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1181 <get_sequence+0x41>
movl   $0x1,0x4(%rsp)
lea    0xe7d(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11bc <get_sequence+0x7c>
mov    %rax,%rbx
mov    0x4(%rsp),%edx
add    $0x1,%edx
lea    0xe61(%rip),%rsi
mov    %rax,%rdi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x4(%rsp),%eax
jmp    11be <get_sequence+0x7e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @get_sequence(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 1, i32* %5
br label %16
11: ; preds = %1
%12 = load i32*, i32** %4
%13 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%14 = load i32*, i32** %4
%15 = call i32 @fclose(i32* %14)
br label %16
16: ; preds = %11, %10
%17 = load i8*, i8** %3
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %18, i32** %4
%19 = load i32*, i32** %4
%20 = icmp ne i32* %19, null
br i1 %20, label %22, label %21
21: ; preds = %16
store i32 0, i32* %2
br label %30
22: ; preds = %16
%23 = load i32*, i32** %4
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = load i32*, i32** %4
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* %5
store i32 %29, i32* %2
br label %30
30: ; preds = %22, %21
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @get_sequence(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %7
6: ; preds = %1
store i32 1, i32* %2
br label %10
7: ; preds = %1
%8 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = call i32 @fclose(i32* %4)
br label %10
10: ; preds = %7, %6
%11 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
%16 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = call i32 @fclose(i32* %11)
%18 = load i32, i32* %2
br label %19
19: ; preds = %10, %13
%20 = phi i32 [ %18, %13 ], [ 0, %10 ]
ret i32 %20
}