#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ createdb();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int importdb(int);
int /*<<< orphan*/ printf(char *);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int main() {
  createdb();
  const int FIRST_LINE = 2;
  char buffer[1024];
  char *record, *line;
  int i = 0, j = 0;
  int mat[100][100];
  FILE *fstream = fopen("cost1.csv", "r");
  if (fstream == NULL) {
    printf("\n file opening failed ");
    return -1;
  }
  int line_count = 0;
  while (fgets(buffer, sizeof(buffer), fstream) != NULL)
    if (++line_count >= FIRST_LINE - 1)
      break;
  while ((line = fgets(buffer, sizeof(buffer), fstream)) != NULL) {
    int value;
    if (sscanf(line, "%*ld,%d", &value) != 1) {
      fprintf(stderr, "sscanf failed.\n");
      exit(EXIT_FAILURE);
    }
    int y = importdb(value);
    if (y != 0) {
      fprintf(stderr, "error:\n ");
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa090,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <createdb@plt>
movl   $0x2,-0x8(%rbp)
movl   $0x0,-0x424(%rbp)
movl   $0x0,-0x428(%rbp)
lea    0xe45(%rip),%rdi
lea    0xe48(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0xa078(%rbp)
cmpq   $0x0,-0xa078(%rbp)
jne    11f4 <main+0x74>
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12f5 <main+0x175>
movl   $0x0,-0xa07c(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0xa078(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1242 <main+0xc2>
mov    -0xa07c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xa07c(%rbp)
cmp    $0x1,%eax
jl     123d <main+0xbd>
jmp    1242 <main+0xc2>
jmp    11fe <main+0x7e>
jmp    1247 <main+0xc7>
lea    -0x410(%rbp),%rdi
mov    -0xa078(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    %rax,-0x420(%rbp)
cmp    $0x0,%rax
je     12ee <main+0x16e>
mov    -0x420(%rbp),%rdi
lea    0xda5(%rip),%rsi
lea    -0xa080(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     12b6 <main+0x136>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xd88(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0xa080(%rbp),%edi
call   1030 <importdb@plt>
mov    %eax,-0xa084(%rbp)
cmpl   $0x0,-0xa084(%rbp)
je     12e9 <main+0x169>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
lea    0xd57(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1247 <main+0xc7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa090,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <createdb@plt>
lea    0xe5f(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1256 <main+0xd6>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %r14,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1267 <main+0xe7>
lea    0xe35(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x10(%rsp),%rbp
mov    0x2de1(%rip),%r14
lea    0xe35(%rip),%r13
jmp    1225 <main+0xa5>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1252 <main+0xd2>
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    127b <main+0xfb>
mov    0xc(%rsp),%edi
call   1030 <importdb@plt>
test   %eax,%eax
je     1210 <main+0x90>
mov    (%r14),%edi
mov    %r13,%rsi
call   1070 <fprintf@plt>
jmp    1210 <main+0x90>
xor    %ebp,%ebp
jmp    1267 <main+0xe7>
lea    0xdaf(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%edi
lea    0xda6(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"cost1.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"\0A file opening failed \00"
@.str.3 = [8 x i8] c"%*ld,%d\00"
@stderr = global i32 0
@.str.4 = [16 x i8] c"sscanf failed.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [9 x i8] c"error:\0A \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [100 x [100 x i32]]
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %1
%13 = call i32 (...) @createdb()
store i32 2, i32* %2
store i32 0, i32* %6
store i32 0, i32* %7
%14 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %9
%15 = load i32*, i32** %9
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %56
19: ; preds = %0
store i32 0, i32* %10
br label %20
20: ; preds = %30, %19
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%22 = load i32*, i32** %9
%23 = call i8* @fgets(i8* %21, i32 1024, i32* %22)
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %31
25: ; preds = %20
%26 = load i32, i32* %10
%27 = add nsw i32 %26, 1
store i32 %27, i32* %10
%28 = icmp sge i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %25
br label %31
30: ; preds = %25
br label %20
31: ; preds = %29, %20
br label %32
32: ; preds = %54, %31
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%34 = load i32*, i32** %9
%35 = call i8* @fgets(i8* %33, i32 1024, i32* %34)
store i8* %35, i8** %5
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %55
37: ; preds = %32
%38 = load i8*, i8** %5
%39 = call i32 @sscanf(i8* %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%40 = icmp ne i32 %39, 1
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %37
%47 = load i32, i32* %11
%48 = call i32 @importdb(i32 %47)
store i32 %48, i32* %12
%49 = load i32, i32* %12
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %51, %46
br label %32
55: ; preds = %32
store i32 0, i32* %1
br label %56
56: ; preds = %55, %17
%57 = load i32, i32* %1
ret i32 %57
}

LLVM IR (-O2):
@.str = [10 x i8] c"cost1.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [23 x i8] c"\0A file opening failed \00"
@.str.3 = [8 x i8] c"%*ld,%d\00"
@stderr = global i32 0
@.str.4 = [16 x i8] c"sscanf failed.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [9 x i8] c"error:\0A \00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = tail call i32 (...) @createdb()
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %34
9: ; preds = %0
%10 = call i8* @fgets(i8* %4, i32 1024, i32* %5)
%11 = call i8* @fgets(i8* %4, i32 1024, i32* %5)
%12 = icmp eq i8* %11, null
br i1 %12, label %34, label %13
13: ; preds = %9
%14 = bitcast i32* %2 to i8*
br label %15
15: ; preds = %13, %31
%16 = phi i8* [ %11, %13 ], [ %32, %31 ]
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%18 = icmp eq i32 %17, 1
br i1 %18, label %24, label %19
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %15
%25 = load i32, i32* %2
%26 = call i32 @importdb(i32 %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %31
31: ; preds = %28, %24
%32 = call i8* @fgets(i8* %4, i32 1024, i32* %5)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %15
34: ; preds = %31, %9, %7
%35 = phi i32 [ -1, %7 ], [ 0, %9 ], [ 0, %31 ]
ret i32 %35
}