#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*/ exit(int);
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 *);
scalar_t__ 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);
  if (system("rm /tmp/rndc_tsar.txt") < 0) {
    exit(-1);
  }
  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    0xe63(%rip),%rdi
lea    0xe53(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c6 <parse_stat_file+0x36>
jmp    1313 <parse_stat_file+0x183>
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     12be <parse_stat_file+0x12e>
lea    -0xa0(%rbp),%rdi
lea    0xe01(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    1222 <parse_stat_file+0x92>
jmp    11d6 <parse_stat_file+0x46>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdd7(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    124c <parse_stat_file+0xbc>
jmp    11d6 <parse_stat_file+0x46>
mov    -0xa8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
jle    128e <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    0xd5b(%rip),%rsi
call   10a0 <sprintf@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
jmp    11d6 <parse_stat_file+0x46>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xd38(%rip),%rdi
call   1050 <system@plt>
cmp    $0x0,%rax
jge    12e7 <parse_stat_file+0x157>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1307 <parse_stat_file+0x177>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1313 <parse_stat_file+0x183>
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    0xe5e(%rip),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1289 <parse_stat_file+0xf9>
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     125d <parse_stat_file+0xcd>
lea    0xe1a(%rip),%r15
mov    %rsp,%rbx
jmp    121e <parse_stat_file+0x8e>
nop
movslq %r13d,%r13
lea    (%r14,%r13,1),%rdi
lea    0xe04(%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     125d <parse_stat_file+0xcd>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     1209 <parse_stat_file+0x79>
xor    %edi,%edi
mov    %r15,%rsi
call   1090 <strtok@plt>
test   %rax,%rax
je     1209 <parse_stat_file+0x79>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11f0 <parse_stat_file+0x60>
mov    %rbp,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
jmp    11f0 <parse_stat_file+0x60>
mov    %r12,%rdi
call   1030 <fclose@plt>
lea    0xd9a(%rip),%rdi
call   1050 <system@plt>
test   %rax,%rax
js     129b <parse_stat_file+0x10b>
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
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

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 %73
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 i64 @system(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 @exit(i32 -1)
unreachable
59: ; preds = %52
%60 = load i32, i32* %4
%61 = icmp sgt i32 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %59
%63 = load i8*, i8** %2
%64 = load i32, i32* %4
%65 = sub nsw i32 %64, 1
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %63, i64 %66
store i8 0, i8* %67
br label %73
68: ; preds = %59
%69 = load i8*, i8** %2
%70 = load i32, i32* %4
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
store i8 0, i8* %72
br label %73
73: ; preds = %10, %68, %62
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 %49, 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 i64 @system(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %35
%43 = icmp sgt i32 %36, 0
%44 = sext i32 %36 to i64
%45 = add nsw i32 %36, -1
%46 = zext i32 %45 to i64
%47 = select i1 %43, i64 %46, i64 %44
%48 = getelementptr inbounds i8, i8* %0, i64 %47
store i8 0, i8* %48
br label %49
49: ; preds = %1, %42
ret void
}