#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 */
scalar_t__ atof(char *);
scalar_t__ atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char *strtok(char *, char *);
int main() {
  int i, one_line_size = 100;
  FILE *fp = NULL;
  char one_line_buf[200] = {};
  char *sep = ",";
  char *one_word = NULL;
  if ((fp = fopen("demo.csv", "r")) == NULL) {
    printf("can not open file");
    return 0;
  }
  while (fgets(one_line_buf, one_line_size, fp) != NULL) {
    one_word = strtok(one_line_buf, sep);
    for (i = 0; i < 3; i++) {
      switch (i) {
      case 0:
        printf("%2d,", (int)(atoi(one_word)));
        break;
      case 1:
        printf("%s,", one_word);
        break;
      case 2:
        printf("%.4f", (double)(atof(one_word)));
        break;
      default:
        break;
      }
      one_word = strtok(NULL, sep);
    }
    printf("\n");
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1060 <memset@plt>
lea    0xe65(%rip),%rax
mov    %rax,-0xe8(%rbp)
movq   $0x0,-0xf0(%rbp)
lea    0xe2c(%rip),%rdi
lea    0xe2e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1208 <main+0x88>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    133f <main+0x1bf>
jmp    120d <main+0x8d>
lea    -0xe0(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     132f <main+0x1af>
lea    -0xe0(%rbp),%rdi
mov    -0xe8(%rbp),%rsi
call   1090 <strtok@plt>
mov    %rax,-0xf0(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    131c <main+0x19c>
mov    -0x8(%rbp),%eax
mov    %eax,-0xf4(%rbp)
test   %eax,%eax
je     1293 <main+0x113>
jmp    126b <main+0xeb>
mov    -0xf4(%rbp),%eax
sub    $0x1,%eax
je     12b4 <main+0x134>
jmp    127f <main+0xff>
mov    -0xf4(%rbp),%eax
sub    $0x2,%eax
je     12ce <main+0x14e>
jmp    12f2 <main+0x172>
mov    -0xf0(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%esi
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f7 <main+0x177>
mov    -0xf0(%rbp),%rsi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12f7 <main+0x177>
mov    -0xf0(%rbp),%rdi
call   1030 <atof@plt>
cvtsi2sd %rax,%xmm0
lea    0xd40(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
jmp    12f7 <main+0x177>
jmp    12f7 <main+0x177>
mov    -0xe8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1090 <strtok@plt>
mov    %rax,-0xf0(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    124b <main+0xcb>
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120d <main+0x8d>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
xorpd  %xmm0,%xmm0
movapd %xmm0,0xb0(%rsp)
movapd %xmm0,0xa0(%rsp)
movapd %xmm0,0x90(%rsp)
movapd %xmm0,0x80(%rsp)
movapd %xmm0,0x70(%rsp)
movapd %xmm0,0x60(%rsp)
movapd %xmm0,0x50(%rsp)
movapd %xmm0,0x40(%rsp)
movapd %xmm0,0x30(%rsp)
movapd %xmm0,0x20(%rsp)
movapd %xmm0,0x10(%rsp)
movapd %xmm0,(%rsp)
movq   $0x0,0xc0(%rsp)
lea    0xe05(%rip),%rdi
lea    0xe07(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12e1 <main+0x161>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12d7 <main+0x157>
lea    0xded(%rip),%rbx
mov    %rsp,%r15
lea    0xde0(%rip),%r12
lea    0xdde(%rip),%r13
lea    0xddb(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   10a0 <atoi@plt>
mov    %r12,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
mov    %rax,%rdi
call   1040 <atof@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    %rbp,%rdi
mov    $0x1,%al
call   1060 <printf@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1090 <strtok@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    $0x64,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
jne    1250 <main+0xd0>
mov    %r14,%rdi
call   1050 <fclose@plt>
jmp    12ef <main+0x16f>
lea    0xd23(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [9 x i8] c"demo.csv\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [18 x i8] c"can not open file\00"
@.str.4 = [5 x i8] c"%2d,\00"
@.str.5 = [4 x i8] c"%s,\00"
@.str.6 = [5 x i8] c"%.4f\00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [200 x i8]
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %1
store i32 100, i32* %3
store i32* null, i32** %4
%8 = bitcast [200 x i8]* %5 to i8*
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* null, i8** %7
%9 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %54
13: ; preds = %0
br label %14
14: ; preds = %49, %13
%15 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%16 = load i32, i32* %3
%17 = load i32*, i32** %4
%18 = call i32* @fgets(i8* %15, i32 %16, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %51
20: ; preds = %14
%21 = getelementptr inbounds [200 x i8], [200 x i8]* %5, i64 0, i64 0
%22 = load i8*, i8** %6
%23 = call i8* @strtok(i8* %21, i8* %22)
store i8* %23, i8** %7
store i32 0, i32* %2
br label %24
24: ; preds = %46, %20
%25 = load i32, i32* %2
%26 = icmp slt i32 %25, 3
br i1 %26, label %27, label %49
27: ; preds = %24
%28 = load i32, i32* %2
switch i32 %28, label %42 [
i32 0, label %29
i32 1, label %34
i32 2, label %37
]
29: ; preds = %27
%30 = load i8*, i8** %7
%31 = call i64 @atoi(i8* %30)
%32 = trunc i64 %31 to i32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %32)
br label %43
34: ; preds = %27
%35 = load i8*, i8** %7
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %35)
br label %43
37: ; preds = %27
%38 = load i8*, i8** %7
%39 = call i64 @atof(i8* %38)
%40 = sitofp i64 %39 to double
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), double %40)
br label %43
42: ; preds = %27
br label %43
43: ; preds = %42, %37, %34, %29
%44 = load i8*, i8** %6
%45 = call i8* @strtok(i8* null, i8* %44)
store i8* %45, i8** %7
br label %46
46: ; preds = %43
%47 = load i32, i32* %2
%48 = add nsw i32 %47, 1
store i32 %48, i32* %2
br label %24
49: ; preds = %24
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
br label %14
51: ; preds = %14
%52 = load i32*, i32** %4
%53 = call i32 @fclose(i32* %52)
store i32 0, i32* %1
br label %54
54: ; preds = %51, %11
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
@.str.1 = [9 x i8] c"demo.csv\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [18 x i8] c"can not open file\00"
@.str.4 = [5 x i8] c"%2d,\00"
@.str.5 = [4 x i8] c"%s,\00"
@.str.6 = [5 x i8] c"%.4f\00"
define i32 @main() {
%1 = alloca [200 x i8]
%2 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32* @fgets(i8* %2, i32 100, i32* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %25, label %10
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %27
10: ; preds = %5, %10
%11 = call i8* @strtok(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = call i64 @atoi(i8* %11)
%13 = trunc i64 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%17 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = call i64 @atof(i8* %17)
%19 = sitofp i64 %18 to double
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), double %19)
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @putchar(i32 10)
%23 = call i32* @fgets(i8* %2, i32 100, i32* %3)
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %10
25: ; preds = %10, %5
%26 = call i32 @fclose(i32* %3)
br label %27
27: ; preds = %25, %8
ret i32 0
}