#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 *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  char door[6000];
  size_t count;
  int signed_count;
  int i;
  for (i = 0; i < 6000; i++) {
    door[i] = 0;
  }
  if (argc < 2) {
    printf("paramenter 1: the door data\n");
    return 0;
  }
  fp = fopen(argv[1], "rb");
  count = fread(door, 22, 256, fp);
  signed_count = (int)count;
  printf("count = %d\n", signed_count);
  for (i = 0; i < signed_count; i++) {
    if (i * 22 >= 6000) {
      printf("Error: buffer overflow: BS: %d i: %d\n", 6000, i);
    } else {
      printf("INSERT INTO door VALUES ('%d', '%s', '');\n", i, door + i * 22);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x17a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x17a0(%rbp)
cmpl   $0x1770,-0x17a0(%rbp)
jge    1196 <main+0x56>
movslq -0x17a0(%rbp),%rax
movb   $0x0,-0x1790(%rbp,%rax,1)
mov    -0x17a0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x17a0(%rbp)
jmp    1163 <main+0x23>
cmpl   $0x2,-0x8(%rbp)
jge    11ba <main+0x7a>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12b0 <main+0x170>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe54(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x1790(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x16,%esi
mov    $0x100,%edx
call   1030 <fread@plt>
mov    %rax,-0x1798(%rbp)
mov    -0x1798(%rbp),%rax
mov    %eax,-0x179c(%rbp)
mov    -0x179c(%rbp),%esi
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x17a0(%rbp)
mov    -0x17a0(%rbp),%eax
cmp    -0x179c(%rbp),%eax
jge    12a0 <main+0x160>
imul   $0x16,-0x17a0(%rbp),%eax
cmp    $0x1770,%eax
jl     1260 <main+0x120>
mov    -0x17a0(%rbp),%edx
lea    0xddd(%rip),%rdi
mov    $0x1770,%esi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1287 <main+0x147>
mov    -0x17a0(%rbp),%esi
lea    -0x1790(%rbp),%rdx
imul   $0x16,-0x17a0(%rbp),%eax
cltq
add    %rax,%rdx
lea    0xdd2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    128c <main+0x14c>
mov    -0x17a0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x17a0(%rbp)
jmp    121e <main+0xde>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x17a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1778,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
mov    $0x1770,%edx
xor    %esi,%esi
call   1070 <memset@plt>
cmp    $0x1,%ebp
jg     119b <main+0x3b>
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
jmp    1241 <main+0xe1>
mov    0x8(%rbx),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x16,%esi
mov    $0x100,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
lea    0xe36(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebx,%ebx
jle    1239 <main+0xd9>
mov    %ebx,%r13d
lea    0xe2b(%rip),%r15
lea    0xe4a(%rip),%r12
xor    %ebp,%ebp
xor    %ebx,%ebx
jmp    121e <main+0xbe>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%eax
lea    (%rsp,%rax,1),%rdx
mov    %r12,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
add    $0x16,%ebp
cmp    %rbx,%r13
je     1239 <main+0xd9>
cmp    $0x1770,%ebp
jb     1200 <main+0xa0>
mov    %r15,%rdi
mov    $0x1770,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1212 <main+0xb2>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x1778,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"paramenter 1: the door data\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [12 x i8] c"count = %d\0A\00"
@.str.3 = [38 x i8] c"Error: buffer overflow: BS: %d i: %d\0A\00"
@.str.4 = [43 x i8] c"INSERT INTO door VALUES ('%d', '%s', '');\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [6000 x i8]
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
br label %11
11: ; preds = %18, %2
%12 = load i32, i32* %10
%13 = icmp slt i32 %12, 6000
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i32, i32* %10
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [6000 x i8], [6000 x i8]* %7, i64 0, i64 %16
store i8 0, i8* %17
br label %18
18: ; preds = %14
%19 = load i32, i32* %10
%20 = add nsw i32 %19, 1
store i32 %20, i32* %10
br label %11
21: ; preds = %11
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 2
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %64
26: ; preds = %21
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %6
%31 = getelementptr inbounds [6000 x i8], [6000 x i8]* %7, i64 0, i64 0
%32 = load i32*, i32** %6
%33 = call i64 @fread(i8* %31, i32 22, i32 256, i32* %32)
store i64 %33, i64* %8
%34 = load i64, i64* %8
%35 = trunc i64 %34 to i32
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %36)
store i32 0, i32* %10
br label %38
38: ; preds = %58, %26
%39 = load i32, i32* %10
%40 = load i32, i32* %9
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %61
42: ; preds = %38
%43 = load i32, i32* %10
%44 = mul nsw i32 %43, 22
%45 = icmp sge i32 %44, 6000
br i1 %45, label %46, label %49
46: ; preds = %42
%47 = load i32, i32* %10
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 6000, i32 %47)
br label %57
49: ; preds = %42
%50 = load i32, i32* %10
%51 = getelementptr inbounds [6000 x i8], [6000 x i8]* %7, i64 0, i64 0
%52 = load i32, i32* %10
%53 = mul nsw i32 %52, 22
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %50, i8* %55)
br label %57
57: ; preds = %49, %46
br label %58
58: ; preds = %57
%59 = load i32, i32* %10
%60 = add nsw i32 %59, 1
store i32 %60, i32* %10
br label %38
61: ; preds = %38
%62 = load i32*, i32** %6
%63 = call i32 @fclose(i32* %62)
store i32 0, i32* %3
br label %64
64: ; preds = %61, %24
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [12 x i8] c"count = %d\0A\00"
@.str.3 = [38 x i8] c"Error: buffer overflow: BS: %d i: %d\0A\00"
@.str.4 = [43 x i8] c"INSERT INTO door VALUES ('%d', '%s', '');\0A\00"
@str = [28 x i8] c"paramenter 1: the door data\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6000 x i8]
%4 = getelementptr inbounds [6000 x i8], [6000 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds [6000 x i8], [6000 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %35
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 @fread(i8* %5, i32 22, i32 256, i32* %12)
%14 = trunc i64 %13 to i32
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = icmp sgt i32 %14, 0
br i1 %16, label %17, label %33
17: ; preds = %9
%18 = and i64 %13, 4294967295
br label %19
19: ; preds = %17, %30
%20 = phi i64 [ 0, %17 ], [ %31, %30 ]
%21 = trunc i64 %20 to i32
%22 = mul nsw i32 %21, 22
%23 = icmp ugt i32 %22, 5999
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i32 6000, i32 %21)
br label %30
26: ; preds = %19
%27 = zext i32 %22 to i64
%28 = getelementptr inbounds [6000 x i8], [6000 x i8]* %3, i64 0, i64 %27
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %21, i8* %28)
br label %30
30: ; preds = %24, %26
%31 = add nuw nsw i64 %20, 1
%32 = icmp eq i64 %31, %18
br i1 %32, label %33, label %19
33: ; preds = %30, %9
%34 = call i32 @fclose(i32* %12)
br label %35
35: ; preds = %33, %7
ret i32 0
}