#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ *strchr(char *, char);
int strlen(char *);
int main(int argc, char *argv[]) {
  FILE *fp;
  char linebuf[1024];
  int buflen;
  int slot;
  int i, k;
  if (argc < 2) {
    printf("parameter 1: FloorAccess.txt\n");
    return 0;
  }
  fp = fopen(argv[1], "r");
  fgets(linebuf, 1024, fp);
  while (fgets(linebuf, 1024, fp) != NULL) {
    if (strchr(linebuf, 'Y') == NULL)
      continue;
    sscanf(linebuf, "%d", &slot);
    if (slot == 0)
      continue;
    k = 1;
    buflen = strlen(linebuf);
    for (i = 5; i < buflen; i++) {
      if (linebuf[i] == ' ')
        continue;
      if (linebuf[i] == 'Y') {
        printf("INSERT INTO floor_access (address,floor) VALUES ('%d','%d');\n",
               slot, k);
      }
      k++;
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ad <main+0x3d>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1304 <main+0x194>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12f4 <main+0x184>
lea    -0x420(%rbp),%rdi
mov    $0x59,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    1219 <main+0xa9>
jmp    11da <main+0x6a>
lea    -0x420(%rbp),%rdi
lea    0xdf9(%rip),%rsi
lea    -0x428(%rbp),%rdx
call   1080 <sscanf@plt>
cmpl   $0x0,-0x428(%rbp)
jne    1245 <main+0xd5>
jmp    11da <main+0x6a>
movl   $0x1,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x424(%rbp)
movl   $0x5,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
cmp    -0x424(%rbp),%eax
jge    12ef <main+0x17f>
movslq -0x42c(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x20,%eax
jne    129a <main+0x12a>
jmp    12db <main+0x16b>
movslq -0x42c(%rbp),%rax
movsbl -0x420(%rbp,%rax,1),%eax
ff
cmp    $0x59,%eax
jne    12cc <main+0x15c>
mov    -0x428(%rbp),%esi
mov    -0x430(%rbp),%edx
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x430(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x430(%rbp)
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    126b <main+0xfb>
jmp    11da <main+0x6a>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
cmp    $0x1,%edi
jg     11a7 <main+0x27>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
jmp    1294 <main+0x114>
mov    0x8(%rsi),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1080 <fgets@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     128c <main+0x10c>
lea    0x10(%rsp),%rbx
lea    0xe11(%rip),%r13
jmp    1215 <main+0x95>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     128c <main+0x10c>
mov    %rbx,%rdi
mov    $0x59,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     1200 <main+0x80>
mov    %rbx,%rdi
lea    0xdd1(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1090 <sscanf@plt>
cmpl   $0x0,0xc(%rsp)
je     1200 <main+0x80>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x6,%eax
jl     1200 <main+0x80>
mov    %eax,%r15d
mov    $0x1,%ebp
mov    $0x5,%r12d
jmp    126c <main+0xec>
nop
add    $0x1,%ebp
add    $0x1,%r12
cmp    %r12,%r15
je     1200 <main+0x80>
movzbl 0x10(%rsp,%r12,1),%eax
cmp    $0x20,%al
je     1263 <main+0xe3>
cmp    $0x59,%al
jne    1260 <main+0xe0>
mov    0xc(%rsp),%esi
mov    %r13,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1260 <main+0xe0>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"parameter 1: FloorAccess.txt\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [62 x i8] c"INSERT INTO floor_access (address,floor) VALUES ('%d','%d');\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %76
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%22 = load i32*, i32** %6
%23 = call i32* @fgets(i8* %21, i32 1024, i32* %22)
br label %24
24: ; preds = %72, %39, %33, %16
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = load i32*, i32** %6
%27 = call i32* @fgets(i8* %25, i32 1024, i32* %26)
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %73
29: ; preds = %24
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%31 = call i32* @strchr(i8* %30, i8 signext 89)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %34
33: ; preds = %29
br label %24
34: ; preds = %29
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%36 = call i32 @sscanf(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %9)
%37 = load i32, i32* %9
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %34
br label %24
40: ; preds = %34
store i32 1, i32* %11
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%42 = call i32 @strlen(i8* %41)
store i32 %42, i32* %8
store i32 5, i32* %10
br label %43
43: ; preds = %69, %40
%44 = load i32, i32* %10
%45 = load i32, i32* %8
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %72
47: ; preds = %43
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 32
br i1 %53, label %54, label %55
54: ; preds = %47
br label %69
55: ; preds = %47
%56 = load i32, i32* %10
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 89
br i1 %61, label %62, label %66
62: ; preds = %55
%63 = load i32, i32* %9
%64 = load i32, i32* %11
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0), i32 %63, i32 %64)
br label %66
66: ; preds = %62, %55
%67 = load i32, i32* %11
%68 = add nsw i32 %67, 1
store i32 %68, i32* %11
br label %69
69: ; preds = %66, %54
%70 = load i32, i32* %10
%71 = add nsw i32 %70, 1
store i32 %71, i32* %10
br label %43
72: ; preds = %43
br label %24
73: ; preds = %24
%74 = load i32*, i32** %6
%75 = call i32 @fclose(i32* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %73, %14
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [62 x i8] c"INSERT INTO floor_access (address,floor) VALUES ('%d','%d');\0A\00"
@str = [29 x i8] c"parameter 1: FloorAccess.txt\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %48
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32* @fgets(i8* %5, i32 1024, i32* %13)
%15 = call i32* @fgets(i8* %5, i32 1024, i32* %13)
%16 = icmp eq i32* %15, null
br i1 %16, label %46, label %17
17: ; preds = %10, %20
%18 = call i32* @strchr(i8* %5, i8 signext 89)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %23
20: ; preds = %42, %27, %17, %23
%21 = call i32* @fgets(i8* %5, i32 1024, i32* %13)
%22 = icmp eq i32* %21, null
br i1 %22, label %46, label %17
23: ; preds = %17
%24 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 0
br i1 %26, label %20, label %27
27: ; preds = %23
%28 = call i32 @strlen(i8* %5)
%29 = icmp sgt i32 %28, 5
br i1 %29, label %30, label %20
30: ; preds = %27
%31 = zext i32 %28 to i64
br label %32
32: ; preds = %30, %42
%33 = phi i64 [ 5, %30 ], [ %44, %42 ]
%34 = phi i32 [ 1, %30 ], [ %43, %42 ]
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %33
%36 = load i8, i8* %35
switch i8 %36, label %40 [
i8 32, label %42
i8 89, label %37
]
37: ; preds = %32
%38 = load i32, i32* %4
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %34)
br label %40
40: ; preds = %32, %37
%41 = add nsw i32 %34, 1
br label %42
42: ; preds = %32, %40
%43 = phi i32 [ %34, %32 ], [ %41, %40 ]
%44 = add nuw nsw i64 %33, 1
%45 = icmp eq i64 %44, %31
br i1 %45, label %20, label %32
46: ; preds = %20, %10
%47 = call i32 @fclose(i32* %13)
br label %48
48: ; preds = %46, %8
ret i32 0
}