#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
char **strsplit(char *, char *, size_t *);
int main() {
  char line[1024];
  FILE *fp;
  char **tokens;
  size_t numtokens;
  fp = fopen("exp.txt", "r");
  if (fp) {
    fgets(line, 1024, fp);
    tokens = strsplit(line, ",", &numtokens);
    for (size_t i = 0; i < numtokens; i++) {
      printf("    token: \"%s\"\n", tokens[i]);
    }
    fclose(fp);
  } else {
    printf("fail - no file\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     122a <main+0xda>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x400,%esi
call   1050 <fgets@plt>
lea    -0x410(%rbp),%rdi
lea    0xe5a(%rip),%rsi
lea    -0x428(%rbp),%rdx
call   1070 <strsplit@plt>
mov    %rax,-0x420(%rbp)
movq   $0x0,-0x430(%rbp)
mov    -0x430(%rbp),%rax
cmp    -0x428(%rbp),%rax
jae    1219 <main+0xc9>
mov    -0x420(%rbp),%rax
mov    -0x430(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x430(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x430(%rbp)
jmp    11ce <main+0x7e>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1238 <main+0xe8>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0xe8b(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11f3 <main+0x93>
mov    %rax,%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
lea    0xe65(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1080 <strsplit@plt>
cmpq   $0x0,0x8(%rsp)
je     11e9 <main+0x89>
mov    %rax,%r12
lea    0xe48(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    (%r12,%rbx,8),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    0x8(%rsp),%rbx
jb     11d0 <main+0x70>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    11ff <main+0x9f>
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"exp.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [17 x i8] c" token: \22%s\22\0A\00"
@.str.4 = [16 x i8] c"fail - no file\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i32*
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i64
store i32 0, i32* %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %32
10: ; preds = %0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%12 = load i32*, i32** %3
%13 = call i32 @fgets(i8* %11, i32 1024, i32* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%15 = call i8** @strsplit(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i64* %5)
store i8** %15, i8*** %4
store i64 0, i64* %6
br label %16
16: ; preds = %26, %10
%17 = load i64, i64* %6
%18 = load i64, i64* %5
%19 = icmp ult i64 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i8**, i8*** %4
%22 = load i64, i64* %6
%23 = getelementptr inbounds i8*, i8** %21, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %20
%27 = load i64, i64* %6
%28 = add i64 %27, 1
store i64 %28, i64* %6
br label %16
29: ; preds = %16
%30 = load i32*, i32** %3
%31 = call i32 @fclose(i32* %30)
br label %34
32: ; preds = %0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %32, %29
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [8 x i8] c"exp.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [17 x i8] c" token: \22%s\22\0A\00"
@str = [15 x i8] c"fail - no file\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca i64
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = bitcast i64* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 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 %22, label %7
7: ; preds = %0
%8 = call i32 @fgets(i8* %3, i32 1024, i32* %5)
%9 = call i8** @strsplit(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i64* %2)
%10 = load i64, i64* %2
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %14, %7
%13 = call i32 @fclose(i32* %5)
br label %24
14: ; preds = %7, %14
%15 = phi i64 [ %19, %14 ], [ 0, %7 ]
%16 = getelementptr inbounds i8*, i8** %9, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = add nuw i64 %15, 1
%20 = load i64, i64* %2
%21 = icmp ult i64 %19, %20
br i1 %21, label %14, label %12
22: ; preds = %0
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %12
ret i32 0
}