#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 */
struct stat {
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, float);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strsep(char **, char *);
float strtof(char *, int /*<<< orphan*/ *);
int db_import(char *fn, char **argv) {
  printf("Starting import from file...\n");
  char *db = argv[0];
  char *inf = argv[1];
  printf("Opening file %s\n", inf);
  FILE *fp = fopen(inf, "r");
  struct stat st = {0};
  char *line = malloc(64);
  while (!feof(fp)) {
    char *tickr;
    char *date;
    int ms;
    float price;
    char *lp = line;
    fscanf(fp, "%s\n", line);
    if (line[0] == '#')
      continue;
    tickr = strsep(&line, ",");
    date = strsep(&line, ".");
    ms = atoi(strsep(&line, ","));
    strsep(&line, ",");
    price = strtof(strsep(&line, ","), NULL);
    char fname1[20], fname2[20];
    sprintf(fname1, "%s_%.8s_%s", tickr, date, date + 8);
    char path[40] = {0};
    strcat(path, db);
    strcat(path, "/unsorted/");
    strcat(path, fname1);
    FILE *fp2 = fopen(path, "a");
    fprintf(fp2, "%d %f\n", ms, price);
    strcat(path, ".gz");
    fclose(fp2);
    line = lp;
  }
  free(line);
  fclose(fp);
}


x86 assembly (clang, -O0):
<db_import>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x30(%rbp)
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    $0x40,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    127a <db_import+0x9a>
jmp    13e6 <db_import+0x206>
mov    -0x40(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x40(%rbp),%rdx
lea    0xd9a(%rip),%rsi
call   1080 <fscanf@plt>
mov    -0x40(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    12ab <db_import+0xcb>
jmp    125c <db_import+0x7c>
lea    -0x40(%rbp),%rdi
lea    0xd7b(%rip),%rsi
call   10c0 <strsep@plt>
mov    %rax,-0x48(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xd69(%rip),%rsi
call   10c0 <strsep@plt>
mov    %rax,-0x50(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xd53(%rip),%rsi
call   10c0 <strsep@plt>
mov    %rax,%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x54(%rbp)
lea    -0x40(%rbp),%rdi
lea    0xd38(%rip),%rsi
call   10c0 <strsep@plt>
lea    -0x40(%rbp),%rdi
lea    0xd28(%rip),%rsi
call   10c0 <strsep@plt>
mov    %rax,%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <strtof@plt>
movss  %xmm0,-0x58(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    -0x50(%rbp),%r8
add    $0x8,%r8
lea    0xcfb(%rip),%rsi
call   1100 <sprintf@plt>
lea    -0xd0(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1070 <memset@plt>
lea    -0xd0(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10f0 <strcat@plt>
lea    -0xd0(%rbp),%rdi
lea    0xcd0(%rip),%rsi
call   10f0 <strcat@plt>
lea    -0xd0(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   10f0 <strcat@plt>
lea    -0xd0(%rbp),%rdi
lea    0xcb8(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xd8(%rbp)
mov    -0xd8(%rbp),%rdi
mov    -0x54(%rbp),%edx
movss  -0x58(%rbp),%xmm0
lea    0xc98(%rip),%rsi
call   1090 <fprintf@plt>
lea    -0xd0(%rbp),%rdi
lea    0xc8c(%rip),%rsi
call   10f0 <strcat@plt>
mov    -0xd8(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x60(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    125c <db_import+0x7c>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_import>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
lea    0xe40(%rip),%rdi
call   1040 <puts@plt>
mov    (%rbx),%r14
mov    0x8(%rbx),%rbx
lea    0xdf5(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf5(%rip),%rsi
mov    %rbx,%rdi
call   10d0 <fopen@plt>
mov    %rax,%r15
mov    $0x40,%edi
call   10b0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,(%rsp)
mov    %r15,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
je     1263 <db_import+0x83>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,0x18(%rsp)
mov    %r14,0x10(%rsp)
jmp    1280 <db_import+0xa0>
nop
mov    %r15,%rdi
call   10a0 <feof@plt>
mov    (%rsp),%rbx
test   %eax,%eax
jne    1244 <db_import+0x64>
mov    %r15,%rdi
lea    0xd83(%rip),%rsi
mov    %rbx,%rdx
call   1080 <fscanf@plt>
mov    (%rsp),%rax
cmpb   $0x23,(%rax)
je     1270 <db_import+0x90>
mov    %rsp,%r13
mov    %r13,%rdi
lea    0xd6b(%rip),%r12
mov    %r12,%rsi
call   10c0 <strsep@plt>
mov    %rax,%rbp
mov    %r13,%rdi
lea    0xd96(%rip),%rsi
call   10c0 <strsep@plt>
mov    %rax,%r14
mov    %r13,%rdi
mov    %r12,%rsi
call   10c0 <strsep@plt>
mov    %rax,%rdi
call   10e0 <atoi@plt>
mov    %eax,%r15d
mov    %r13,%rdi
mov    %r12,%rsi
call   10c0 <strsep@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   10c0 <strsep@plt>
mov    %rax,%rdi
xor    %esi,%esi
call   1070 <strtof@plt>
movss  %xmm0,0xc(%rsp)
lea    0x8(%r14),%r8
lea    0x50(%rsp),%r12
mov    %r12,%rdi
lea    0xd01(%rip),%rsi
mov    %rbp,%rdx
mov    0x10(%rsp),%rbp
mov    %r14,%rcx
call   1100 <sprintf@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x40(%rsp)
lea    0x20(%rsp),%r13
mov    %r13,%rdi
mov    %rbp,%rsi
call   10f0 <strcat@plt>
mov    %r13,%rdi
lea    0xccc(%rip),%rsi
call   10f0 <strcat@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   10f0 <strcat@plt>
mov    %r13,%rdi
lea    0xcbd(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xcad(%rip),%rsi
mov    %r15d,%edx
mov    0x18(%rsp),%r15
movss  0xc(%rsp),%xmm0
call   1090 <fprintf@plt>
mov    %r13,%rdi
lea    0xc97(%rip),%rsi
call   10f0 <strcat@plt>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %rbx,(%rsp)
jmp    1270 <db_import+0x90>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [30 x i8] c"Starting import from file...\0A\00"
@.str.1 = [17 x i8] c"Opening file %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c",\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [11 x i8] c"%s_%.8s_%s\00"
@.str.7 = [11 x i8] c"/unsorted/\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [7 x i8] c"%d %f\0A\00"
@.str.10 = [4 x i8] c".gz\00"
define i32 @db_import(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca %struct.stat
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca float
%15 = alloca i8*
%16 = alloca [20 x i8]
%17 = alloca [20 x i8]
%18 = alloca [40 x i8]
%19 = alloca i32*
store i8* %0, i8** %4
store i8** %1, i8*** %5
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
store i8* %23, i8** %6
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i8*, i8** %7
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %30, i32** %8
%31 = bitcast %struct.stat* %9 to i8*
%32 = call i8* @malloc(i32 64)
store i8* %32, i8** %10
br label %33
33: ; preds = %49, %48, %2
%34 = load i32*, i32** %8
%35 = call i32 @feof(i32* %34)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %38, label %83
38: ; preds = %33
%39 = load i8*, i8** %10
store i8* %39, i8** %15
%40 = load i32*, i32** %8
%41 = load i8*, i8** %10
%42 = call i32 @fscanf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %41)
%43 = load i8*, i8** %10
%44 = getelementptr inbounds i8, i8* %43, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 35
br i1 %47, label %48, label %49
48: ; preds = %38
br label %33
49: ; preds = %38
%50 = call i8* @strsep(i8** %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %50, i8** %11
%51 = call i8* @strsep(i8** %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %51, i8** %12
%52 = call i8* @strsep(i8** %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%53 = call i32 @atoi(i8* %52)
store i32 %53, i32* %13
%54 = call i8* @strsep(i8** %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%55 = call i8* @strsep(i8** %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%56 = call float @strtof(i8* %55, i32* null)
store float %56, float* %14
%57 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%58 = load i8*, i8** %11
%59 = load i8*, i8** %12
%60 = load i8*, i8** %12
%61 = getelementptr inbounds i8, i8* %60, i64 8
%62 = call i32 @sprintf(i8* %57, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %58, i8* %59, i8* %61)
%63 = bitcast [40 x i8]* %18 to i8*
%64 = getelementptr inbounds [40 x i8], [40 x i8]* %18, i64 0, i64 0
%65 = load i8*, i8** %6
%66 = call i32 @strcat(i8* %64, i8* %65)
%67 = getelementptr inbounds [40 x i8], [40 x i8]* %18, i64 0, i64 0
%68 = call i32 @strcat(i8* %67, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%69 = getelementptr inbounds [40 x i8], [40 x i8]* %18, i64 0, i64 0
%70 = getelementptr inbounds [20 x i8], [20 x i8]* %16, i64 0, i64 0
%71 = call i32 @strcat(i8* %69, i8* %70)
%72 = getelementptr inbounds [40 x i8], [40 x i8]* %18, i64 0, i64 0
%73 = call i32* @fopen(i8* %72, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %73, i32** %19
%74 = load i32*, i32** %19
%75 = load i32, i32* %13
%76 = load float, float* %14
%77 = call i32 @fprintf(i32* %74, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %75, float %76)
%78 = getelementptr inbounds [40 x i8], [40 x i8]* %18, i64 0, i64 0
%79 = call i32 @strcat(i8* %78, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%80 = load i32*, i32** %19
%81 = call i32 @fclose(i32* %80)
%82 = load i8*, i8** %15
store i8* %82, i8** %10
br label %33
83: ; preds = %33
%84 = load i8*, i8** %10
%85 = call i32 @free(i8* %84)
%86 = load i32*, i32** %8
%87 = call i32 @fclose(i32* %86)
%88 = load i32, i32* %3
ret i32 %88
}

LLVM IR (-O2):
@.str.1 = [17 x i8] c"Opening file %s\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c",\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [11 x i8] c"%s_%.8s_%s\00"
@.str.7 = [11 x i8] c"/unsorted/\00"
@.str.8 = [2 x i8] c"a\00"
@.str.9 = [7 x i8] c"%d %f\0A\00"
@.str.10 = [4 x i8] c".gz\00"
@str = [29 x i8] c"Starting import from file...\00"
define i32 @db_import(i8* nocapture readnone %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca [20 x i8]
%5 = alloca [40 x i8]
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%7 = load i8*, i8** %1
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = bitcast i8** %3 to i8*
%13 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
store i8* %13, i8** %3
%14 = call i32 @feof(i32* %11)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %46
16: ; preds = %2
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
br label %19
19: ; preds = %42, %16
%20 = phi i8* [ %13, %16 ], [ %45, %42 ]
%21 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 35
br i1 %24, label %42, label %25
25: ; preds = %19
%26 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%27 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%28 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @atoi(i8* %28)
%30 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%31 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = call float @strtof(i8* nocapture %31, i32* null)
%33 = getelementptr inbounds i8, i8* %27, i64 8
%34 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i8* %26, i8* %27, i8* %33)
%35 = call i32 @strcat(i8* %18, i8* %7)
%36 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%37 = call i32 @strcat(i8* %18, i8* %17)
%38 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%39 = call i32 @fprintf(i32* %38, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %29, float %32)
%40 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%41 = call i32 @fclose(i32* %38)
store i8* %20, i8** %3
br label %42
42: ; preds = %19, %25
%43 = call i32 @feof(i32* %11)
%44 = icmp eq i32 %43, 0
%45 = load i8*, i8** %3
br i1 %44, label %19, label %46
46: ; preds = %42, %2
%47 = phi i8* [ %13, %2 ], [ %45, %42 ]
%48 = call i32 @free(i8* %47)
%49 = call i32 @fclose(i32* %11)
ret i32 undef
}