#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, long long);
int /*<<< orphan*/ sscanf(char *, char *, long *);
int main(int argc, char *argv[]) {
  long quantity = 0;
  long long total = 0;
  FILE *datfile = fopen("data/transactions.csv", "r");
  char dump[1000 + 1];
  fgets(dump, 1000, datfile);
  long linenum = 0;
  while (!feof(datfile)) {
    linenum++;
    if (linenum % 1000000 == 0)
      printf("current total: %lld\n", total);
    fgets(dump, 1000, datfile);
    sscanf(dump, "%*ld,%*ld,%*ld,%*ld,%*ld,%*ld,%*25[^,],%*ld,%*30[^,],%ld,%*s",
           &quantity);
    total += quantity;
  }
  printf("Total quantity count: %lld\n", total);
}


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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x3e8,%esi
call   1040 <fgets@plt>
movq   $0x0,-0x428(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ce <main+0x7e>
jmp    1248 <main+0xf8>
mov    -0x428(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    120b <main+0xbb>
mov    -0x20(%rbp),%rsi
lea    0xe12(%rip),%rdi
call   1030 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x3e8,%esi
call   1040 <fgets@plt>
lea    -0x420(%rbp),%rdi
lea    0xdff(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    11b0 <main+0x60>
mov    -0x20(%rbp),%rsi
lea    0xe17(%rip),%rdi
call   1030 <printf@plt>
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    $0x408,%rsp
movq   $0x0,0x8(%rsp)
lea    0xe8f(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x3e8,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
mov    %r14,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     11c4 <main+0x74>
xor    %r15d,%r15d
lea    0xec2(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffffffffffff,%rbp
mov    $0x1,%ebx
xor    %r15d,%r15d
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%r12
jmp    121b <main+0xcb>
nop
mov    %r13,%rdi
mov    $0x3e8,%esi
mov    %r14,%rdx
call   1040 <fgets@plt>
mov    %r13,%rdi
lea    0xe33(%rip),%rsi
mov    %r12,%rdx
call   1060 <sscanf@plt>
add    0x8(%rsp),%r15
mov    %r14,%rdi
call   1050 <feof@plt>
add    $0xffffffffffffffff,%rbp
add    $0x1,%rbx
test   %eax,%eax
jne    11a1 <main+0x51>
mov    %rbx,%rax
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mul    %rcx
shr    $0x12,%rdx
imul   $0xf4240,%rdx,%rax
add    %rbp,%rax
jne    11e0 <main+0x90>
lea    0xdd6(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
jmp    11e0 <main+0x90>

LLVM IR (-O0):
@.str = [22 x i8] c"data/transactions.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"current total: %lld\0A\00"
@.str.3 = [61 x i8] c"%*ld,%*ld,%*ld,%*ld,%*ld,%*ld,%*25[^,],%*ld,%*30[^,],%ld,%*s\00"
@.str.4 = [28 x i8] c"Total quantity count: %lld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
%9 = alloca [1001 x i8]
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i64 0, i64* %7
%11 = call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %8
%12 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
%13 = load i32*, i32** %8
%14 = call i32 @fgets(i8* %12, i32 1000, i32* %13)
store i64 0, i64* %10
br label %15
15: ; preds = %29, %2
%16 = load i32*, i32** %8
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %38
20: ; preds = %15
%21 = load i64, i64* %10
%22 = add nsw i64 %21, 1
store i64 %22, i64* %10
%23 = load i64, i64* %10
%24 = srem i64 %23, 1000000
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = load i64, i64* %7
%28 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 %27)
br label %29
29: ; preds = %26, %20
%30 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
%31 = load i32*, i32** %8
%32 = call i32 @fgets(i8* %30, i32 1000, i32* %31)
%33 = getelementptr inbounds [1001 x i8], [1001 x i8]* %9, i64 0, i64 0
%34 = call i32 @sscanf(i8* %33, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), i64* %6)
%35 = load i64, i64* %6
%36 = load i64, i64* %7
%37 = add nsw i64 %36, %35
store i64 %37, i64* %7
br label %15
38: ; preds = %15
%39 = load i64, i64* %7
%40 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i64 %39)
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [22 x i8] c"data/transactions.csv\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"current total: %lld\0A\00"
@.str.3 = [61 x i8] c"%*ld,%*ld,%*ld,%*ld,%*ld,%*ld,%*25[^,],%*ld,%*30[^,],%ld,%*s\00"
@.str.4 = [28 x i8] c"Total quantity count: %lld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i64
%4 = alloca [1001 x i8]
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = getelementptr inbounds [1001 x i8], [1001 x i8]* %4, i64 0, i64 0
%8 = call i32 @fgets(i8* %7, i32 1000, i32* %6)
%9 = call i32 @feof(i32* %6)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %26
11: ; preds = %2, %19
%12 = phi i64 [ %14, %19 ], [ 0, %2 ]
%13 = phi i64 [ %23, %19 ], [ 0, %2 ]
%14 = add nuw nsw i64 %12, 1
%15 = urem i64 %14, 1000000
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 %13)
br label %19
19: ; preds = %17, %11
%20 = call i32 @fgets(i8* %7, i32 1000, i32* %6)
%21 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), i64* %3)
%22 = load i64, i64* %3
%23 = add nsw i64 %22, %13
%24 = call i32 @feof(i32* %6)
%25 = icmp eq i32 %24, 0
br i1 %25, label %11, label %26
26: ; preds = %19, %2
%27 = phi i64 [ 0, %2 ], [ %23, %19 ]
%28 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i64 %27)
ret i32 0
}