#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
size_t getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ mkqueue(char *, int, char *);
int parsemaxwrks(char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
char *strsep(char **, char *);
int loadqueues(char *cf) {
  FILE *f;
  char *line = NULL, *p, *col, *name, *cmd;
  int r = 0, l, max;
  size_t size = 0;
  size_t len;
  if (!(f = fopen(cf, "r"))) {
    fprintf(stderr, "unable to open config: %s\n", cf);
    return -1;
  }
  for (l = 0; (len = getline(&line, &size, f)) != -1; l++) {
    p = line;
    if (line[0] == '#' || line[0] == '\n' || line[0] == '\0') {
      continue;
    }
    col = strsep(&p, " \t");
    if (!col) {
      fprintf(stderr, "error: failed to parse `name` field on line %d\n",
              l + 1);
      r = -1;
      break;
    }
    name = strdup(col);
    col = strsep(&p, " \t");
    if (!col || (max = parsemaxwrks(col)) < 0) {
      fprintf(stderr, "error: failed to parse `maxworkers` on line %d\n",
              l + 1);
      r = -1;
      break;
    }
    col = strsep(&p, "\n");
    if (!col) {
      fprintf(stderr, "error: missing `cmd` field on line %d\n", l + 1);
      r = -1;
      break;
    }
    cmd = strdup(col);
    if (mkqueue(name, max, cmd) > 0) {
      fprintf(stderr, "queue `%s` already exists", name);
    }
  }
  free(line);
  fclose(f);
  return r;
}


x86 assembly (clang, -O0):
<loadqueues>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x44(%rbp)
movq   $0x0,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11f8 <loadqueues+0x68>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe1d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c2 <loadqueues+0x232>
movl   $0x0,-0x48(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   1090 <getline@plt>
mov    %rax,-0x60(%rbp)
cmp    $0xffffffffffffffff,%rax
je     13aa <loadqueues+0x21a>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
je     1256 <loadqueues+0xc6>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     1256 <loadqueues+0xc6>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    125b <loadqueues+0xcb>
jmp    139c <loadqueues+0x20c>
lea    -0x28(%rbp),%rdi
lea    0xdb7(%rip),%rsi
call   1070 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12a3 <loadqueues+0x113>
mov    0x2d5f(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%edx
add    $0x1,%edx
lea    0xd90(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x44(%rbp)
jmp    13aa <loadqueues+0x21a>
mov    -0x30(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x38(%rbp)
lea    -0x28(%rbp),%rdi
lea    0xd62(%rip),%rsi
call   1070 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12e4 <loadqueues+0x154>
mov    -0x30(%rbp),%rdi
call   1060 <parsemaxwrks@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
jge    130d <loadqueues+0x17d>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%edx
add    $0x1,%edx
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x44(%rbp)
jmp    13aa <loadqueues+0x21a>
lea    -0x28(%rbp),%rdi
lea    0xd66(%rip),%rsi
call   1070 <strsep@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1355 <loadqueues+0x1c5>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%edx
add    $0x1,%edx
lea    0xd3e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x44(%rbp)
jmp    13aa <loadqueues+0x21a>
mov    -0x30(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x4c(%rbp),%esi
mov    -0x40(%rbp),%rdx
call   10a0 <mkqueue@plt>
cmp    $0x0,%rax
jle    1397 <loadqueues+0x207>
mov    0x2c5d(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    139c <loadqueues+0x20c>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11ff <loadqueues+0x6f>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loadqueues>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbp
movq   $0x0,(%rsp)
movq   $0x0,0x18(%rsp)
lea    0xe47(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1308 <loadqueues+0x178>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x18(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
cmp    $0xffffffffffffffff,%rax
je     1304 <loadqueues+0x174>
mov    $0x1,%ebp
lea    0x20(%rsp),%r12
mov    %rsp,%r14
lea    0x18(%rsp),%r13
movabs $0x800000401,%r15
mov    %rbx,0x8(%rsp)
jmp    122b <loadqueues+0x9b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
cmp    $0xffffffffffffffff,%rax
je     1304 <loadqueues+0x174>
mov    (%rsp),%rax
mov    %rax,0x20(%rsp)
movzbl (%rax),%eax
cmp    $0x23,%rax
ja     1243 <loadqueues+0xb3>
bt     %rax,%r15
jb     1210 <loadqueues+0x80>
mov    %rbx,%r15
mov    %r12,%rdi
lea    0xdcd(%rip),%rbx
mov    %rbx,%rsi
call   1070 <strsep@plt>
test   %rax,%rax
je     1329 <loadqueues+0x199>
mov    %rax,%rdi
call   10b0 <strdup@plt>
mov    %rax,0x10(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <strsep@plt>
test   %rax,%rax
je     1332 <loadqueues+0x1a2>
mov    %r12,%rbx
mov    %rax,%rdi
call   1060 <parsemaxwrks@plt>
test   %eax,%eax
js     133e <loadqueues+0x1ae>
mov    %eax,%r12d
mov    %rbx,%rdi
lea    0xddc(%rip),%rsi
call   1070 <strsep@plt>
test   %rax,%rax
je     1347 <loadqueues+0x1b7>
mov    %rax,%rdi
call   10b0 <strdup@plt>
mov    0x10(%rsp),%rdi
mov    %r12d,%esi
mov    %rax,%rdx
call   10a0 <mkqueue@plt>
test   %rax,%rax
mov    %rbx,%r12
mov    0x8(%rsp),%rbx
movabs $0x800000401,%r15
jle    1210 <loadqueues+0x80>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1210 <loadqueues+0x80>
xor    %ebp,%ebp
jmp    136a <loadqueues+0x1da>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
lea    0xcea(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    137b <loadqueues+0x1eb>
lea    0xcf0(%rip),%rsi
jmp    1339 <loadqueues+0x1a9>
lea    0xd17(%rip),%rsi
mov    %r15,%rbx
jmp    1353 <loadqueues+0x1c3>
lea    0xd0b(%rip),%rsi
jmp    134e <loadqueues+0x1be>
lea    0xd32(%rip),%rsi
mov    0x8(%rsp),%rbx
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"unable to open config: %s\0A\00"
@.str.2 = [3 x i8] c" \09\00"
@.str.3 = [48 x i8] c"error: failed to parse `name` field on line %d\0A\00"
@.str.4 = [48 x i8] c"error: failed to parse `maxworkers` on line %d\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [39 x i8] c"error: missing `cmd` field on line %d\0A\00"
@.str.7 = [26 x i8] c"queue `%s` already exists\00"
define i32 @loadqueues(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
store i8* %0, i8** %3
store i8* null, i8** %5
store i32 0, i32* %10
store i64 0, i64* %13
%15 = load i8*, i8** %3
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %4
%17 = icmp ne i32* %16, null
br i1 %17, label %22, label %18
18: ; preds = %1
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %3
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %20)
store i32 -1, i32* %2
br label %102
22: ; preds = %1
store i32 0, i32* %11
br label %23
23: ; preds = %93, %22
%24 = load i32*, i32** %4
%25 = call i64 @getline(i8** %5, i64* %13, i32* %24)
store i64 %25, i64* %14
%26 = icmp ne i64 %25, -1
br i1 %26, label %27, label %96
27: ; preds = %23
%28 = load i8*, i8** %5
store i8* %28, i8** %6
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 35
br i1 %33, label %46, label %34
34: ; preds = %27
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 10
br i1 %39, label %46, label %40
40: ; preds = %34
%41 = load i8*, i8** %5
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %40, %34, %27
br label %93
47: ; preds = %40
%48 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %48, i8** %7
%49 = load i8*, i8** %7
%50 = icmp ne i8* %49, null
br i1 %50, label %56, label %51
51: ; preds = %47
%52 = load i32, i32* @stderr
%53 = load i32, i32* %11
%54 = add nsw i32 %53, 1
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %54)
store i32 -1, i32* %10
br label %96
56: ; preds = %47
%57 = load i8*, i8** %7
%58 = call i8* @strdup(i8* %57)
store i8* %58, i8** %8
%59 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i8* %59, i8** %7
%60 = load i8*, i8** %7
%61 = icmp ne i8* %60, null
br i1 %61, label %62, label %66
62: ; preds = %56
%63 = load i8*, i8** %7
%64 = call i32 @parsemaxwrks(i8* %63)
store i32 %64, i32* %12
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %71
66: ; preds = %62, %56
%67 = load i32, i32* @stderr
%68 = load i32, i32* %11
%69 = add nsw i32 %68, 1
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i32 %69)
store i32 -1, i32* %10
br label %96
71: ; preds = %62
%72 = call i8* @strsep(i8** %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i8* %72, i8** %7
%73 = load i8*, i8** %7
%74 = icmp ne i8* %73, null
br i1 %74, label %80, label %75
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = load i32, i32* %11
%78 = add nsw i32 %77, 1
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i32 %78)
store i32 -1, i32* %10
br label %96
80: ; preds = %71
%81 = load i8*, i8** %7
%82 = call i8* @strdup(i8* %81)
store i8* %82, i8** %9
%83 = load i8*, i8** %8
%84 = load i32, i32* %12
%85 = load i8*, i8** %9
%86 = call i64 @mkqueue(i8* %83, i32 %84, i8* %85)
%87 = icmp sgt i64 %86, 0
br i1 %87, label %88, label %92
88: ; preds = %80
%89 = load i32, i32* @stderr
%90 = load i8*, i8** %8
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %90)
br label %92
92: ; preds = %88, %80
br label %93
93: ; preds = %92, %46
%94 = load i32, i32* %11
%95 = add nsw i32 %94, 1
store i32 %95, i32* %11
br label %23
96: ; preds = %75, %66, %51, %23
%97 = load i8*, i8** %5
%98 = call i32 @free(i8* %97)
%99 = load i32*, i32** %4
%100 = call i32 @fclose(i32* %99)
%101 = load i32, i32* %10
store i32 %101, i32* %2
br label %102
102: ; preds = %96, %18
%103 = load i32, i32* %2
ret i32 %103
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"unable to open config: %s\0A\00"
@.str.2 = [3 x i8] c" \09\00"
@.str.3 = [48 x i8] c"error: failed to parse `name` field on line %d\0A\00"
@.str.4 = [48 x i8] c"error: failed to parse `maxworkers` on line %d\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [39 x i8] c"error: missing `cmd` field on line %d\0A\00"
@.str.7 = [26 x i8] c"queue `%s` already exists\00"
define i32 @loadqueues(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%6 = bitcast i8** %3 to i8*
%7 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = call i64 @getline(i8** %2, i64* %4, i32* %8)
%12 = icmp eq i64 %11, -1
br i1 %12, label %48, label %16
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %53
16: ; preds = %10, %40
%17 = phi i32 [ %41, %40 ], [ 1, %10 ]
%18 = load i8*, i8** %2
store i8* %18, i8** %3
%19 = load i8, i8* %18
switch i8 %19, label %20 [
i8 35, label %40
i8 10, label %40
i8 0, label %40
]
20: ; preds = %16
%21 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %44, label %23
23: ; preds = %20
%24 = call i8* @strdup(i8* %21)
%25 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %44, label %27
27: ; preds = %23
%28 = call i32 @parsemaxwrks(i8* %25)
%29 = icmp slt i32 %28, 0
br i1 %29, label %44, label %30
30: ; preds = %27
%31 = call i8* @strsep(i8** %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %44, label %33
33: ; preds = %30
%34 = call i8* @strdup(i8* %31)
%35 = call i64 @mkqueue(i8* %24, i32 %28, i8* %34)
%36 = icmp sgt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %24)
br label %40
40: ; preds = %16, %16, %16, %33, %37
%41 = add i32 %17, 1
%42 = call i64 @getline(i8** %2, i64* %4, i32* %8)
%43 = icmp eq i64 %42, -1
br i1 %43, label %48, label %16
44: ; preds = %30, %23, %27, %20
%45 = phi i8* [ getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), %20 ], [ getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), %27 ], [ getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), %23 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), %30 ]
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* %45, i32 %17)
br label %48
48: ; preds = %40, %44, %10
%49 = phi i32 [ 0, %10 ], [ -1, %44 ], [ 0, %40 ]
%50 = load i8*, i8** %2
%51 = call i32 @free(i8* %50)
%52 = call i32 @fclose(i32* %8)
br label %53
53: ; preds = %48, %13
%54 = phi i32 [ %49, %48 ], [ -1, %13 ]
ret i32 %54
}