void test_jnx_file() {
  system("echo 'whats up' > tmp.txt");
  char *buffer;
  int size = jnx_file_read("tmp.txt", &buffer, "r");
  char *test_string = "whats up\n";
  while (*buffer != '\0') {
    char a = *buffer;
    char b = *test_string;
    if (a != b) {
      jnx_log(0,
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/AlexsJones/jnxlibc/refs/heads/master/"
              "test/unit/test_jnxfile.c",
              __FUNCTION__, 50, "%X %X do not match\n", a, b);
      ;
    }
    assert(a == b);
    test_string++;
    buffer++;
  }
  system("rm tmp.txt");
}


x86 assembly (clang, -O0):
<test_jnx_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x0,%al
call   1030 <system@plt>
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    0xeb2(%rip),%rdx
mov    $0x0,%al
call   1060 <jnx_file_read@plt>
mov    %eax,-0xc(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1214 <test_jnx_file+0xd4>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x1a(%rbp)
movsbl -0x19(%rbp),%eax
movsbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
je     11de <test_jnx_file+0x9e>
movsbl -0x19(%rbp),%r9d
movsbl -0x1a(%rbp),%eax
xor    %edi,%edi
lea    0xe65(%rip),%rsi
lea    0xef6(%rip),%rdx
mov    $0x32,%ecx
lea    0xef8(%rip),%r8
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <jnx_log@plt>
movsbl -0x19(%rbp),%eax
movsbl -0x1a(%rbp),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    117d <test_jnx_file+0x3d>
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <system@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_jnx_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1030 <system@plt>
lea    0xeaf(%rip),%rdi
lea    0xeb0(%rip),%rdx
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1060 <jnx_file_read@plt>
mov    0x10(%rsp),%rax
mov    (%rax),%bl
test   %bl,%bl
je     11f4 <test_jnx_file+0xb4>
lea    0xe94(%rip),%r13
lea    0xe97(%rip),%r14
lea    0xf28(%rip),%r15
lea    0xf2f(%rip),%r12
jmp    11ca <test_jnx_file+0x8a>
nop
xor    %edi,%edi
cmp    %bpl,%bl
sete   %dil
xor    %eax,%eax
call   1050 <assert@plt>
add    $0x1,%r13
mov    0x10(%rsp),%rax
lea    0x1(%rax),%rcx
mov    %rcx,0x10(%rsp)
movzbl 0x1(%rax),%ebx
test   %bl,%bl
je     11f4 <test_jnx_file+0xb4>
movsbl 0x0(%r13),%ebp
cmp    %bpl,%bl
je     11a0 <test_jnx_file+0x60>
movsbl %bl,%r9d
mov    %ebp,(%rsp)
xor    %edi,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    $0x32,%ecx
mov    %r12,%r8
xor    %eax,%eax
call   1040 <jnx_log@plt>
jmp    11a0 <test_jnx_file+0x60>
lea    0xee5(%rip),%rdi
xor    %eax,%eax
call   1030 <system@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"echo 'whats up' > tmp.txt\00"
@.str.1 = [8 x i8] c"tmp.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [10 x i8] c"whats up\0A\00"
@.str.4 = [152 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AlexsJones/jnxlibc/refs/heads/master/test/unit/test_jnxfile.c\00"
@__FUNCTION__.test_jnx_file = [14 x i8] c"test_jnx_file\00"
@.str.5 = [20 x i8] c"%X %X do not match\0A\00"
@.str.6 = [11 x i8] c"rm tmp.txt\00"
define void @test_jnx_file() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
%6 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, i8**, i8*, ...) bitcast (i32 (...)* @jnx_file_read to i32 (i8*, i8**, i8*, ...)*)(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32 %7, i32* %2
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %8
8: ; preds = %29, %0
%9 = load i8*, i8** %1
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %41
13: ; preds = %8
%14 = load i8*, i8** %1
%15 = load i8, i8* %14
store i8 %15, i8* %4
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
store i8 %17, i8* %5
%18 = load i8, i8* %4
%19 = sext i8 %18 to i32
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %19, %21
br i1 %22, label %23, label %29
23: ; preds = %13
%24 = load i8, i8* %4
%25 = sext i8 %24 to i32
%26 = load i8, i8* %5
%27 = sext i8 %26 to i32
%28 = call i32 (i32, i8*, i8*, i32, i8*, i32, i32, ...) bitcast (i32 (...)* @jnx_log to i32 (i32, i8*, i8*, i32, i8*, i32, i32, ...)*)(i32 0, i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__FUNCTION__.test_jnx_file, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %25, i32 %27)
br label %29
29: ; preds = %23, %13
%30 = load i8, i8* %4
%31 = sext i8 %30 to i32
%32 = load i8, i8* %5
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %31, %33
%35 = zext i1 %34 to i32
%36 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %35)
%37 = load i8*, i8** %3
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %3
%39 = load i8*, i8** %1
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %1
br label %8
41: ; preds = %8
%42 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"echo 'whats up' > tmp.txt\00"
@.str.1 = [8 x i8] c"tmp.txt\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [10 x i8] c"whats up\0A\00"
@.str.4 = [152 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/AlexsJones/jnxlibc/refs/heads/master/test/unit/test_jnxfile.c\00"
@__FUNCTION__.test_jnx_file = [14 x i8] c"test_jnx_file\00"
@.str.5 = [20 x i8] c"%X %X do not match\0A\00"
@.str.6 = [11 x i8] c"rm tmp.txt\00"
define void @test_jnx_file() {
%1 = alloca i8*
%2 = tail call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%3 = bitcast i8** %1 to i8*
%4 = call i32 (i8*, i8**, i8*, ...) bitcast (i32 (...)* @jnx_file_read to i32 (i8*, i8**, i8*, ...)*)(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = load i8*, i8** %1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %0, %17
%9 = phi i8 [ %23, %17 ], [ %6, %0 ]
%10 = phi i8* [ %20, %17 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), %0 ]
%11 = load i8, i8* %10
%12 = icmp eq i8 %9, %11
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = sext i8 %9 to i32
%15 = sext i8 %11 to i32
%16 = call i32 (i32, i8*, i8*, i32, i8*, i32, i32, ...) bitcast (i32 (...)* @jnx_log to i32 (i32, i8*, i8*, i32, i8*, i32, i32, ...)*)(i32 0, i8* getelementptr inbounds ([152 x i8], [152 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @__FUNCTION__.test_jnx_file, i64 0, i64 0), i32 50, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %14, i32 %15)
br label %17
17: ; preds = %13, %8
%18 = zext i1 %12 to i32
%19 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %18)
%20 = getelementptr inbounds i8, i8* %10, i64 1
%21 = load i8*, i8** %1
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %1
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %8
25: ; preds = %17, %0
%26 = call i32 (i8*, ...) bitcast (i32 (...)* @system to i32 (i8*, ...)*)(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
ret void
}