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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, ...);
char *strtok(char *, char *);
int main(int argc, char *argv[]) {
  int n, m;
  double sum = 0;
  char buff[1024];
  if (argc != 2)
    return EXIT_FAILURE;
  FILE *fd = fopen(argv[1], "r");
  if (fd == NULL)
    return EXIT_FAILURE;
  fgets(buff, (sizeof(buff) / sizeof((buff)[0])), fd);
  sscanf(buff, "%d %d", &n, &m);
  printf("Reading %d lines by %d chars \n\n", n, m);
  for (int i = 0; i < n; i++) {
    double d;
    unsigned int read_nums = 0;
    fgets(buff, (sizeof(buff) / sizeof((buff)[0])), fd);
    printf("%s", buff);
    char *s;
    s = strtok(buff, " ");
    while (s != NULL) {
      if (read_nums >= m)
        break;
      int status = sscanf(s, "%lf", &d);
      if (status != 1)
        return EXIT_FAILURE;
      read_nums++;
      sum += d;
      s = strtok(NULL, " ");
    }
  }
  printf("\nsum is: %lf\n", sum);
  fclose(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119c <main+0x3c>
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    136c <main+0x20c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe55(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    11d6 <main+0x76>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    136c <main+0x20c>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
lea    -0x420(%rbp),%rdi
lea    0xe06(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x42c(%rbp)
mov    -0x42c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1341 <main+0x1e1>
movl   $0x0,-0x43c(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
lea    -0x420(%rbp),%rsi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x420(%rbp),%rdi
lea    0xdae(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
je     1328 <main+0x1c8>
mov    -0x43c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jb     12ab <main+0x14b>
jmp    1328 <main+0x1c8>
mov    -0x448(%rbp),%rdi
lea    0xd74(%rip),%rsi
lea    -0x438(%rbp),%rdx
mov    $0x0,%al
call   1060 <sscanf@plt>
mov    %eax,-0x44c(%rbp)
cmpl   $0x1,-0x44c(%rbp)
je     12eb <main+0x18b>
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    136c <main+0x20c>
mov    -0x43c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x43c(%rbp)
movsd  -0x438(%rbp),%xmm0
ff
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd14(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x448(%rbp)
jmp    1289 <main+0x129>
jmp    132d <main+0x1cd>
mov    -0x42c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x42c(%rbp)
jmp    1229 <main+0xc9>
movsd  -0x20(%rbp),%xmm0
lea    0xce4(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x428(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2c71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
cmp    $0x2,%edi
jne    12bd <main+0x15d>
mov    0x8(%rsi),%rdi
lea    0xe7b(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12bd <main+0x15d>
mov    %rax,%rbx
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
lea    0xe50(%rip),%rsi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <sscanf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
lea    0xe33(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmpl   $0x0,0xc(%rsp)
jle    12d8 <main+0x178>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xe33(%rip),%r13
lea    0x18(%rsp),%r12
xor    %r15d,%r15d
jmp    121f <main+0xbf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r15d
cmp    0xc(%rsp),%r15d
jge    12e2 <main+0x182>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
lea    0xded(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     1210 <main+0xb0>
cmpl   $0x0,0x8(%rsp)
je     1210 <main+0xb0>
mov    $0x1,%r14d
lea    0xdc4(%rip),%rbp
nopl   0x0(%rax)
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    12bd <main+0x15d>
movsd  0x10(%rsp),%xmm0
addsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %edi,%edi
mov    %r13,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     1210 <main+0xb0>
lea    0x1(%r14),%ecx
cmp    0x8(%rsp),%r14d
mov    %ecx,%r14d
jb     1270 <main+0x110>
jmp    1210 <main+0xb0>
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xd48(%rip),%rdi
movsd  0x10(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0x2cd3(%rip),%rax
jmp    12c4 <main+0x164>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [32 x i8] c"Reading %d lines by %d chars \0A\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [4 x i8] c"%lf\00"
@.str.6 = [14 x i8] c"\0Asum is: %lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca [1024 x i8]
%10 = alloca i32*
%11 = alloca i32
%12 = alloca double
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %8
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %20
18: ; preds = %2
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %82
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %24, i32** %10
%25 = load i32*, i32** %10
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %82
29: ; preds = %20
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%31 = load i32*, i32** %10
%32 = call i32 @fgets(i8* %30, i32 1024, i32* %31)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%34 = call i32 (i8*, i8*, ...) @sscanf(i8* %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %6, i32* %7)
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %35, i32 %36)
store i32 0, i32* %11
br label %38
38: ; preds = %73, %29
%39 = load i32, i32* %11
%40 = load i32, i32* %6
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %76
42: ; preds = %38
store i32 0, i32* %13
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%44 = load i32*, i32** %10
%45 = call i32 @fgets(i8* %43, i32 1024, i32* %44)
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%49 = call i8* @strtok(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %49, i8** %14
br label %50
50: ; preds = %65, %42
%51 = load i8*, i8** %14
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %72
53: ; preds = %50
%54 = load i32, i32* %13
%55 = load i32, i32* %7
%56 = icmp uge i32 %54, %55
br i1 %56, label %57, label %58
57: ; preds = %53
br label %72
58: ; preds = %53
%59 = load i8*, i8** %14
%60 = call i32 (i8*, i8*, ...) @sscanf(i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double* %12)
store i32 %60, i32* %15
%61 = load i32, i32* %15
%62 = icmp ne i32 %61, 1
br i1 %62, label %63, label %65
63: ; preds = %58
%64 = load i32, i32* @EXIT_FAILURE
store i32 %64, i32* %3
br label %82
65: ; preds = %58
%66 = load i32, i32* %13
%67 = add i32 %66, 1
store i32 %67, i32* %13
%68 = load double, double* %12
%69 = load double, double* %8
%70 = fadd double %69, %68
store double %70, double* %8
%71 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i8* %71, i8** %14
br label %50
72: ; preds = %57, %50
br label %73
73: ; preds = %72
%74 = load i32, i32* %11
%75 = add nsw i32 %74, 1
store i32 %75, i32* %11
br label %38
76: ; preds = %38
%77 = load double, double* %8
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), double %77)
%79 = load i32*, i32** %10
%80 = call i32 @fclose(i32* %79)
%81 = load i32, i32* @EXIT_SUCCESS
store i32 %81, i32* %3
br label %82
82: ; preds = %76, %63, %27, %18
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"%d %d\00"
@.str.2 = [32 x i8] c"Reading %d lines by %d chars \0A\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [4 x i8] c"%lf\00"
@.str.6 = [14 x i8] c"\0Asum is: %lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca double
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = icmp eq i32 %0, 2
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = load i32, i32* @EXIT_FAILURE
br label %67
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = load i32, i32* @EXIT_FAILURE
br label %67
20: ; preds = %13
%21 = call i32 @fgets(i8* %9, i32 1024, i32* %16)
%22 = call i32 (i8*, i8*, ...) @sscanf(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32* %3, i32* %4)
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %24)
%26 = load i32, i32* %3
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %62
28: ; preds = %20
%29 = bitcast double* %6 to i8*
br label %30
30: ; preds = %28, %55
%31 = phi i32 [ 0, %28 ], [ %57, %55 ]
%32 = phi double [ 0.000000e+00, %28 ], [ %56, %55 ]
%33 = call i32 @fgets(i8* %9, i32 1024, i32* %16)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%35 = call i8* @strtok(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%36 = icmp ne i8* %35, null
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
%39 = select i1 %36, i1 %38, i1 false
br i1 %39, label %40, label %55
40: ; preds = %30, %46
%41 = phi i8* [ %50, %46 ], [ %35, %30 ]
%42 = phi i32 [ %47, %46 ], [ 0, %30 ]
%43 = phi double [ %49, %46 ], [ %32, %30 ]
%44 = call i32 (i8*, i8*, ...) @sscanf(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), double* %6)
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %60
46: ; preds = %40
%47 = add nuw i32 %42, 1
%48 = load double, double* %6
%49 = fadd double %43, %48
%50 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%51 = icmp ne i8* %50, null
%52 = load i32, i32* %4
%53 = icmp ult i32 %47, %52
%54 = select i1 %51, i1 %53, i1 false
br i1 %54, label %40, label %55
55: ; preds = %46, %30
%56 = phi double [ %32, %30 ], [ %49, %46 ]
%57 = add nuw nsw i32 %31, 1
%58 = load i32, i32* %3
%59 = icmp slt i32 %57, %58
br i1 %59, label %30, label %62
60: ; preds = %40
%61 = load i32, i32* @EXIT_FAILURE
br label %67
62: ; preds = %55, %20
%63 = phi double [ 0.000000e+00, %20 ], [ %56, %55 ]
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), double %63)
%65 = call i32 @fclose(i32* %16)
%66 = load i32, i32* @EXIT_SUCCESS
br label %67
67: ; preds = %60, %18, %62, %11
%68 = phi i32 [ %12, %11 ], [ %19, %18 ], [ %66, %62 ], [ %61, %60 ]
ret i32 %68
}