#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*/ exit(int /*<<< orphan*/);
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 rw_option(char rw, int nb, int n) {
  int nu[2];
  FILE *fp;
  if ((fp = fopen("data/option.ini", "r")) == NULL || n >= 2) {
    fclose(fp);
    exit(0);
  }
  fscanf(fp, "password = %d", &nu[0]);
  fclose(fp);
  switch (rw) {
  case 'r':
    if (nu[n] < 1)
      return 1;
    return nu[n];
  case 'w':
    if ((fp = fopen("data/option.ini", "w")) == NULL) {
      fclose(fp);
      exit(0);
    }
    if (nb < 1)
      nu[n] = 1;
    else
      nu[n] = nb;
    fprintf(fp, "password = %d", nu[0]);
    fclose(fp);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rw_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xe95(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     118f <rw_option+0x3f>
cmpl   $0x2,-0x10(%rbp)
jl     119f <rw_option+0x4f>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
lea    0xe68(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movsbl -0x5(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x72,%eax
je     11e2 <rw_option+0x92>
jmp    11d1 <rw_option+0x81>
mov    -0x24(%rbp),%eax
sub    $0x77,%eax
je     120d <rw_option+0xbd>
jmp    128c <rw_option+0x13c>
movslq -0x10(%rbp),%rax
cmpl   $0x1,-0x18(%rbp,%rax,4)
jge    11fd <rw_option+0xad>
movl   $0x1,-0x4(%rbp)
jmp    1293 <rw_option+0x143>
movslq -0x10(%rbp),%rax
mov    -0x18(%rbp,%rax,4),%eax
mov    %eax,-0x4(%rbp)
jmp    1293 <rw_option+0x143>
lea    0xdec(%rip),%rdi
lea    0xe05(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    123e <rw_option+0xee>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1070 <exit@plt>
cmpl   $0x1,-0xc(%rbp)
jge    1259 <rw_option+0x109>
movslq -0x10(%rbp),%rax
movl   $0x1,-0x18(%rbp,%rax,4)
jmp    1264 <rw_option+0x114>
mov    -0xc(%rbp),%ecx
movslq -0x10(%rbp),%rax
mov    %ecx,-0x18(%rbp,%rax,4)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xda0(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1293 <rw_option+0x143>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rw_option>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%ebp
lea    0xe9a(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
cmp    $0x1,%r15d
jg     1219 <rw_option+0xc9>
test   %rbx,%rbx
je     1219 <rw_option+0xc9>
lea    0xe83(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
movsbl %bpl,%eax
cmp    $0x77,%eax
je     11c4 <rw_option+0x74>
xor    %ebp,%ebp
cmp    $0x72,%eax
jne    120c <rw_option+0xbc>
movslq %r15d,%rax
mov    (%rsp,%rax,4),%eax
test   %eax,%eax
mov    $0x1,%ebp
cmovg  %eax,%ebp
jmp    120c <rw_option+0xbc>
lea    0xe35(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     121e <rw_option+0xce>
mov    %rax,%rbx
movslq %r15d,%rax
test   %r14d,%r14d
mov    $0x1,%ebp
cmovle %ebp,%r14d
mov    %r14d,(%rsp,%rax,4)
mov    (%rsp),%edx
lea    0xe16(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
jmp    1220 <rw_option+0xd0>
xor    %edi,%edi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"data/option.ini\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"password = %d\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @rw_option(i8 signext %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2 x i32]
%9 = alloca i32*
store i8 %0, i8* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %9
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = load i32, i32* %7
%14 = icmp sge i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %12, %3
%16 = load i32*, i32** %9
%17 = call i32 @fclose(i32* %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %12
%20 = load i32*, i32** %9
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%22 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %21)
%23 = load i32*, i32** %9
%24 = call i32 @fclose(i32* %23)
%25 = load i8, i8* %5
%26 = sext i8 %25 to i32
switch i32 %26, label %65 [
i32 114, label %27
i32 119, label %39
]
27: ; preds = %19
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 %29
%31 = load i32, i32* %30
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 1, i32* %4
br label %66
34: ; preds = %27
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 %36
%38 = load i32, i32* %37
store i32 %38, i32* %4
br label %66
39: ; preds = %19
%40 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %40, i32** %9
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i32*, i32** %9
%44 = call i32 @fclose(i32* %43)
%45 = call i32 @exit(i32 0)
unreachable
46: ; preds = %39
%47 = load i32, i32* %6
%48 = icmp slt i32 %47, 1
br i1 %48, label %49, label %53
49: ; preds = %46
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 %51
store i32 1, i32* %52
br label %58
53: ; preds = %46
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 %56
store i32 %54, i32* %57
br label %58
58: ; preds = %53, %49
%59 = load i32*, i32** %9
%60 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%61 = load i32, i32* %60
%62 = call i32 @fprintf(i32* %59, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %61)
%63 = load i32*, i32** %9
%64 = call i32 @fclose(i32* %63)
store i32 1, i32* %4
br label %66
65: ; preds = %19
store i32 0, i32* %4
br label %66
66: ; preds = %65, %58, %34, %33
%67 = load i32, i32* %4
ret i32 %67
}

LLVM IR (-O2):
@.str = [16 x i8] c"data/option.ini\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [14 x i8] c"password = %d\00"
@.str.3 = [2 x i8] c"w\00"
define i32 @rw_option(i8 signext %0, i32 %1, i32 %2) {
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %4 to i8*
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
%8 = icmp sgt i32 %2, 1
%9 = or i1 %8, %7
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = tail call i32 @fclose(i32* %6)
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %3
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%15 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* %14)
%16 = call i32 @fclose(i32* %6)
%17 = sext i8 %0 to i32
switch i32 %17, label %38 [
i32 114, label %18
i32 119, label %24
]
18: ; preds = %13
%19 = sext i32 %2 to i64
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = icmp sgt i32 %21, 1
%23 = select i1 %22, i32 %21, i32 1
br label %38
24: ; preds = %13
%25 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call i32 @fclose(i32* null)
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %24
%31 = sext i32 %2 to i64
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 %31
%33 = icmp sgt i32 %1, 1
%34 = select i1 %33, i32 %1, i32 1
store i32 %34, i32* %32
%35 = load i32, i32* %14
%36 = call i32 @fprintf(i32* %25, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = call i32 @fclose(i32* %25)
br label %38
38: ; preds = %13, %18, %30
%39 = phi i32 [ 1, %30 ], [ %23, %18 ], [ 0, %13 ]
ret i32 %39
}