#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*/ buf;
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*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *, char *,
                           char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *strchr(char *, char);
int /*<<< orphan*/ unlink(char *);
int convertlist(char *section, char *parampattern, char *fname, char *fil,
                FILE *outfile) {
  char xbuf[4096];
  char buf[2048];
  char entry[2000];
  int cnt = 0;
  char *pt;
  FILE *listfile;
  listfile = fopen(fil, "r");
  if (listfile == NULL)
    return 0x0;
  while (fgets(buf, sizeof(buf), listfile)) {
    pt = strchr(buf, '\n');
    if (pt != NULL)
      *pt = 0;
    pt = strchr(buf, ':');
    if (pt != NULL)
      *pt = ';';
    if (strchr(buf, '#') != buf) {
      sprintf(entry, parampattern, cnt);
      fprintf(outfile, "%s.%s.%s=%s\n", fname, section, entry, buf);
      cnt++;
    }
  }
  fclose(listfile);
  unlink(fil);
  return 0x0;
}


x86 assembly (clang, -O0):
<convertlist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2020,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x0,-0x2004(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x2018(%rbp)
cmpq   $0x0,-0x2018(%rbp)
jne    11ca <convertlist+0x5a>
movl   $0x0,-0x4(%rbp)
jmp    12de <convertlist+0x16e>
jmp    11cf <convertlist+0x5f>
lea    -0x1830(%rbp),%rdi
mov    -0x2018(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     12c2 <convertlist+0x152>
lea    -0x1830(%rbp),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
mov    %rax,-0x2010(%rbp)
cmpq   $0x0,-0x2010(%rbp)
je     1221 <convertlist+0xb1>
mov    -0x2010(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1830(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x2010(%rbp)
cmpq   $0x0,-0x2010(%rbp)
je     1251 <convertlist+0xe1>
mov    -0x2010(%rbp),%rax
movb   $0x3b,(%rax)
lea    -0x1830(%rbp),%rdi
mov    $0x23,%esi
call   1050 <strchr@plt>
lea    -0x1830(%rbp),%rcx
cmp    %rcx,%rax
je     12bd <convertlist+0x14d>
lea    -0x2000(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2004(%rbp),%edx
call   1090 <sprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x2000(%rbp),%r8
lea    -0x1830(%rbp),%r9
lea    0xd59(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x2004(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2004(%rbp)
jmp    11cf <convertlist+0x5f>
mov    -0x2018(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertlist>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xff8,%rsp
mov    %r8,0x18(%rsp)
mov    %rcx,%r14
mov    %rdx,0x10(%rsp)
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0xe65(%rip),%rsi
mov    %rcx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1279 <convertlist+0x109>
mov    %rax,%rbp
mov    %r14,0x8(%rsp)
lea    0x7f0(%rsp),%r14
mov    %r14,%rdi
mov    $0x800,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1267 <convertlist+0xf7>
xor    %r15d,%r15d
lea    0x20(%rsp),%r12
jmp    11f5 <convertlist+0x85>
nop
mov    %r14,%rdi
mov    $0x800,%esi
mov    %rbp,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1267 <convertlist+0xf7>
mov    %r14,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     120a <convertlist+0x9a>
movb   $0x0,(%rax)
mov    %r14,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     121f <convertlist+0xaf>
movb   $0x3b,(%rax)
mov    %r14,%rdi
mov    $0x23,%esi
call   1050 <strchr@plt>
cmp    %r14,%rax
je     11e0 <convertlist+0x70>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1090 <sprintf@plt>
mov    0x18(%rsp),%rdi
lea    0xdb7(%rip),%rsi
mov    0x10(%rsp),%rdx
mov    %rbx,%rcx
mov    %r12,%r8
mov    %r14,%r9
call   1070 <fprintf@plt>
add    $0x1,%r15d
jmp    11e0 <convertlist+0x70>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
add    $0xff8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [13 x i8] c"%s.%s.%s=%s\0A\00"
define i32 @convertlist(i8* %0, i8* %1, i8* %2, i8* %3, i32* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
%12 = alloca [4096 x i8]
%13 = alloca [2048 x i8]
%14 = alloca [2000 x i8]
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i32*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i32* %4, i32** %11
store i32 0, i32* %15
%18 = load i8*, i8** %10
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %17
%20 = load i32*, i32** %17
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %5
store i32 0, i32* %6
br label %67
23: ; preds = %5
br label %24
24: ; preds = %61, %23
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%26 = load i32*, i32** %17
%27 = call i64 @fgets(i8* %25, i32 2048, i32* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %62
29: ; preds = %24
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%31 = call i8* @strchr(i8* %30, i8 signext 10)
store i8* %31, i8** %16
%32 = load i8*, i8** %16
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = load i8*, i8** %16
store i8 0, i8* %35
br label %36
36: ; preds = %34, %29
%37 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%38 = call i8* @strchr(i8* %37, i8 signext 58)
store i8* %38, i8** %16
%39 = load i8*, i8** %16
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = load i8*, i8** %16
store i8 59, i8* %42
br label %43
43: ; preds = %41, %36
%44 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%45 = call i8* @strchr(i8* %44, i8 signext 35)
%46 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%47 = icmp ne i8* %45, %46
br i1 %47, label %48, label %61
48: ; preds = %43
%49 = getelementptr inbounds [2000 x i8], [2000 x i8]* %14, i64 0, i64 0
%50 = load i8*, i8** %8
%51 = load i32, i32* %15
%52 = call i32 @sprintf(i8* %49, i8* %50, i32 %51)
%53 = load i32*, i32** %11
%54 = load i8*, i8** %9
%55 = load i8*, i8** %7
%56 = getelementptr inbounds [2000 x i8], [2000 x i8]* %14, i64 0, i64 0
%57 = getelementptr inbounds [2048 x i8], [2048 x i8]* %13, i64 0, i64 0
%58 = call i32 @fprintf(i32* %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %54, i8* %55, i8* %56, i8* %57)
%59 = load i32, i32* %15
%60 = add nsw i32 %59, 1
store i32 %60, i32* %15
br label %61
61: ; preds = %48, %43
br label %24
62: ; preds = %24
%63 = load i32*, i32** %17
%64 = call i32 @fclose(i32* %63)
%65 = load i8*, i8** %10
%66 = call i32 @unlink(i8* %65)
store i32 0, i32* %6
br label %67
67: ; preds = %62, %22
%68 = load i32, i32* %6
ret i32 %68
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [13 x i8] c"%s.%s.%s=%s\0A\00"
define i32 @convertlist(i8* %0, i8* nocapture %1, i8* %2, i8* nocapture %3, i32* nocapture %4) {
%6 = alloca [2048 x i8]
%7 = alloca [2000 x i8]
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [2000 x i8], [2000 x i8]* %7, i64 0, i64 0
%10 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %38, label %12
12: ; preds = %5
%13 = call i64 @fgets(i8* %8, i32 2048, i32* %10)
%14 = icmp eq i64 %13, 0
br i1 %14, label %35, label %15
15: ; preds = %12, %31
%16 = phi i32 [ %32, %31 ], [ 0, %12 ]
%17 = call i8* @strchr(i8* %8, i8 signext 10)
%18 = icmp eq i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %15
store i8 0, i8* %17
br label %20
20: ; preds = %19, %15
%21 = call i8* @strchr(i8* %8, i8 signext 58)
%22 = icmp eq i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %20
store i8 59, i8* %21
br label %24
24: ; preds = %23, %20
%25 = call i8* @strchr(i8* %8, i8 signext 35)
%26 = icmp eq i8* %25, %8
br i1 %26, label %31, label %27
27: ; preds = %24
%28 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) %1, i32 %16)
%29 = call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %0, i8* %9, i8* %8)
%30 = add nsw i32 %16, 1
br label %31
31: ; preds = %27, %24
%32 = phi i32 [ %30, %27 ], [ %16, %24 ]
%33 = call i64 @fgets(i8* %8, i32 2048, i32* %10)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %15
35: ; preds = %31, %12
%36 = call i32 @fclose(i32* %10)
%37 = call i32 @unlink(i8* %3)
br label %38
38: ; preds = %5, %35
ret i32 0
}