#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*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ sprintf(char *, char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int /*<<< orphan*/ system(char *);
void parse_stat_file(char buf[]) {
  FILE *fp = fopen("/tmp/rndc_tsar.txt", "r");
  if (!fp)
    return;
  rewind(fp);
  int pos = 0;
  char line[128];
  while (fgets(line, 128, fp)) {
    char *s = strtok(line, ",");
    if (!s)
      continue;
    s = strtok(NULL, ",");
    if (!s)
      continue;
    if (strlen(s) > 0)
      s[strlen(s) - 1] = '\0';
    pos += sprintf(buf + pos, "%s,", s);
  }
  fclose(fp);
  system("rm /tmp/rndc_tsar.txt");
  if (pos > 0)
    buf[pos - 1] = '\0';
  else
    buf[pos] = '\0';
}


x86 assembly (clang, -O0):
<parse_stat_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe73(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b6 <parse_stat_file+0x36>
jmp    12ef <parse_stat_file+0x16f>
mov    -0x10(%rbp),%rdi
call   1060 <rewind@plt>
movl   $0x0,-0x14(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12ae <parse_stat_file+0x12e>
lea    -0xa0(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    1212 <parse_stat_file+0x92>
jmp    11c6 <parse_stat_file+0x46>
xor    %eax,%eax
mov    %eax,%edi
lea    0xde7(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    123c <parse_stat_file+0xbc>
jmp    11c6 <parse_stat_file+0x46>
mov    -0xa8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    127e <parse_stat_file+0xfe>
mov    -0xa8(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0xa8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0xb0(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0xa8(%rbp),%rdx
lea    0xd6b(%rip),%rsi
call   10a0 <sprintf@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    11c6 <parse_stat_file+0x46>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd48(%rip),%rdi
call   1050 <system@plt>
cmpl   $0x0,-0x14(%rbp)
jle    12e3 <parse_stat_file+0x163>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    12ef <parse_stat_file+0x16f>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_stat_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%r14
lea    0xe6e(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1274 <parse_stat_file+0xf4>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <rewind@plt>
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     124d <parse_stat_file+0xcd>
lea    0xe2a(%rip),%r15
mov    %rsp,%rbx
jmp    120e <parse_stat_file+0x8e>
nop
movslq %r13d,%r13
lea    (%r14,%r13,1),%rdi
lea    0xe14(%rip),%rsi
mov    %rbp,%rdx
call   10a0 <sprintf@plt>
add    %eax,%r13d
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     124d <parse_stat_file+0xcd>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     11f9 <parse_stat_file+0x79>
xor    %edi,%edi
mov    %r15,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     11f9 <parse_stat_file+0x79>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11e0 <parse_stat_file+0x60>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
jmp    11e0 <parse_stat_file+0x60>
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    0xdaa(%rip),%rdi
call   1050 <system@plt>
lea    -0x1(%r13),%eax
test   %r13d,%r13d
movslq %r13d,%rcx
cmovle %rcx,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/tmp/rndc_tsar.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [4 x i8] c"%s,\00"
@.str.4 = [22 x i8] c"rm /tmp/rndc_tsar.txt\00"
define void @parse_stat_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = alloca i8*
store i8* %0, i8** %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 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 %11, label %10
10: ; preds = %1
br label %69
11: ; preds = %1
%12 = load i32*, i32** %3
%13 = call i32 @rewind(i32* %12)
store i32 0, i32* %4
br label %14
14: ; preds = %41, %29, %24, %11
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%16 = load i32*, i32** %3
%17 = call i64 @fgets(i8* %15, i32 128, i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %52
19: ; preds = %14
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%21 = call i8* @strtok(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = icmp ne i8* %22, null
br i1 %23, label %25, label %24
24: ; preds = %19
br label %14
25: ; preds = %19
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %25
br label %14
30: ; preds = %25
%31 = load i8*, i8** %6
%32 = call i32 @strlen(i8* %31)
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %30
%35 = load i8*, i8** %6
%36 = load i8*, i8** %6
%37 = call i32 @strlen(i8* %36)
%38 = sub nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %35, i64 %39
store i8 0, i8* %40
br label %41
41: ; preds = %34, %30
%42 = load i8*, i8** %2
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8*, i8** %6
%47 = call i64 @sprintf(i8* %45, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %46)
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = add nsw i64 %49, %47
%51 = trunc i64 %50 to i32
store i32 %51, i32* %4
br label %14
52: ; preds = %14
%53 = load i32*, i32** %3
%54 = call i32 @fclose(i32* %53)
%55 = call i32 @system(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%56 = load i32, i32* %4
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %52
%59 = load i8*, i8** %2
%60 = load i32, i32* %4
%61 = sub nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
store i8 0, i8* %63
br label %69
64: ; preds = %52
%65 = load i8*, i8** %2
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %65, i64 %67
store i8 0, i8* %68
br label %69
69: ; preds = %10, %64, %58
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"/tmp/rndc_tsar.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c",\00"
@.str.3 = [4 x i8] c"%s,\00"
@.str.4 = [22 x i8] c"rm /tmp/rndc_tsar.txt\00"
define void @parse_stat_file(i8* %0) {
%2 = alloca [128 x i8]
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %45, label %5
5: ; preds = %1
%6 = tail call i32 @rewind(i32* %3)
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%8 = call i64 @fgets(i8* %7, i32 128, i32* %3)
%9 = icmp eq i64 %8, 0
br i1 %9, label %35, label %10
10: ; preds = %5, %31
%11 = phi i32 [ %32, %31 ], [ 0, %5 ]
%12 = call i8* @strtok(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i8* %12, null
br i1 %13, label %31, label %14
14: ; preds = %10
%15 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %31, label %17
17: ; preds = %14
%18 = call i32 @strlen(i8* %15)
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = call i32 @strlen(i8* %15)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %15, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %20, %17
%26 = sext i32 %11 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
%28 = call i64 @sprintf(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%29 = trunc i64 %28 to i32
%30 = add i32 %11, %29
br label %31
31: ; preds = %14, %10, %25
%32 = phi i32 [ %30, %25 ], [ %11, %10 ], [ %11, %14 ]
%33 = call i64 @fgets(i8* %7, i32 128, i32* %3)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %10
35: ; preds = %31, %5
%36 = phi i32 [ 0, %5 ], [ %32, %31 ]
%37 = call i32 @fclose(i32* %3)
%38 = call i32 @system(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp sgt i32 %36, 0
%40 = sext i32 %36 to i64
%41 = add nsw i32 %36, -1
%42 = zext i32 %41 to i64
%43 = select i1 %39, i64 %42, i64 %40
%44 = getelementptr inbounds i8, i8* %0, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %1, %35
ret void
}