#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*/ entbuf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ cap_getent(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int sscanf(char *, char *, int *);
char *strchr(char *, char);
scalar_t__ strcmp(char *, char const *);
scalar_t__ strncmp(char *, char const *, int);
char *strtok_r(char *, char *, char **);
int cap_getint(const char *path, const char *entname, const char *strname,
               int *val) {
  FILE *fp;
  char *cp, *tp;
  char *lcp, *ltp;
  static int rlev = 0;
  int retval = -1;
  char entbuf[2048];
  if (++rlev > 32)
    return -1;
  fp = fopen(path, "r");
  if (fp == NULL)
    goto Exit;
  while (cap_getent(fp, entbuf, sizeof(entbuf)) > 0) {
    tp = strchr(entbuf, ':');
    *tp++ = '\0';
    cp = strtok_r(entbuf, "|", &lcp);
    while (cp) {
      if (strcmp(cp, entname) == 0) {
        tp = strtok_r(tp, ":", &ltp);
        while (tp) {
          if (strncmp(tp, strname, 2) == 0 && tp[2] == '#') {
            retval = sscanf(tp + 3, "%d", val);
            goto Exit;
          } else if (strncmp(tp, "tc=", 3) == 0) {
            retval = cap_getint(path, tp + 3, strname, val);
            if (retval)
              goto Exit;
          }
          tp = strtok_r(NULL, ":", &ltp);
        }
        goto Exit;
      }
      cp = strtok_r(NULL, "|", &lcp);
    }
  }
Exit:
  --rlev;
  if (fp)
    fclose(fp);
  return retval;
}


x86 assembly (clang, -O0):
<cap_getint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0xffffffff,-0x54(%rbp)
mov    0x2eb4(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2eab(%rip)
cmp    $0x20,%eax
jle    11d6 <cap_getint+0x46>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b8 <cap_getint+0x228>
mov    -0x10(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11fa <cap_getint+0x6a>
jmp    138f <cap_getint+0x1ff>
jmp    11ff <cap_getint+0x6f>
mov    -0x30(%rbp),%rdi
lea    -0x860(%rbp),%rsi
mov    $0x800,%edx
call   10a0 <cap_getent@plt>
cmp    $0x0,%rax
jle    138a <cap_getint+0x1fa>
lea    -0x860(%rbp),%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x40(%rbp)
movb   $0x0,(%rax)
lea    -0x860(%rbp),%rdi
lea    0xdaf(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1385 <cap_getint+0x1f5>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1368 <cap_getint+0x1d8>
mov    -0x40(%rbp),%rdi
lea    0xd77(%rip),%rsi
lea    -0x50(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1363 <cap_getint+0x1d3>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12f2 <cap_getint+0x162>
mov    -0x40(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x23,%eax
jne    12f2 <cap_getint+0x162>
mov    -0x40(%rbp),%rdi
add    $0x3,%rdi
mov    -0x28(%rbp),%rdx
lea    0xd21(%rip),%rsi
call   1090 <sscanf@plt>
mov    %eax,-0x54(%rbp)
jmp    138f <cap_getint+0x1ff>
mov    -0x40(%rbp),%rdi
lea    0xd0c(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1341 <cap_getint+0x1b1>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
add    $0x3,%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <cap_getint@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
je     133c <cap_getint+0x1ac>
jmp    138f <cap_getint+0x1ff>
jmp    1341 <cap_getint+0x1b1>
jmp    1346 <cap_getint+0x1b6>
xor    %eax,%eax
mov    %eax,%edi
lea    0xcb3(%rip),%rsi
lea    -0x50(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x40(%rbp)
jmp    129a <cap_getint+0x10a>
jmp    138f <cap_getint+0x1ff>
xor    %eax,%eax
mov    %eax,%edi
lea    0xc8f(%rip),%rsi
lea    -0x48(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x38(%rbp)
jmp    1260 <cap_getint+0xd0>
jmp    11ff <cap_getint+0x6f>
jmp    138f <cap_getint+0x1ff>
mov    0x2cd7(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2cce(%rip)
cmpq   $0x0,-0x30(%rbp)
je     13b2 <cap_getint+0x222>
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x860,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cap_getint>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x838,%rsp
mov    %rcx,%r15
mov    0x2ec2(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2eb9(%rip)
mov    $0xffffffff,%r14d
cmp    $0x1f,%eax
jg     1382 <cap_getint+0x1f2>
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0xe2e(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1294 <cap_getint+0x104>
lea    0x30(%rsp),%rsi
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
mov    $0x800,%edx
call   10a0 <cap_getent@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
jle    1371 <cap_getint+0x1e1>
mov    %r12,0x10(%rsp)
mov    %rbp,0x18(%rsp)
mov    %r15,(%rsp)
lea    0x30(%rsp),%rbp
lea    0xde2(%rip),%r12
lea    0x28(%rsp),%r13
jmp    124b <cap_getint+0xbb>
nopw   0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x800,%edx
call   10a0 <cap_getent@plt>
test   %rax,%rax
jle    1371 <cap_getint+0x1e1>
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1060 <strchr@plt>
mov    %rbp,%rdi
mov    %rax,%r15
movb   $0x0,(%rax)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <strtok_r@plt>
test   %rax,%rax
je     1230 <cap_getint+0xa0>
mov    %rax,%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12a0 <cap_getint+0x110>
xor    %edi,%edi
jmp    1270 <cap_getint+0xe0>
addl   $0xffffffff,0x2dd1(%rip)
jmp    1382 <cap_getint+0x1f2>
add    $0x1,%r15
lea    0xd59(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %r15,%rdi
call   1070 <strtok_r@plt>
test   %rax,%rax
mov    0x10(%rsp),%rbx
je     1371 <cap_getint+0x1e1>
mov    %rax,%r15
mov    $0xffffffff,%r14d
lea    0xd33(%rip),%r13
lea    0xd27(%rip),%rbp
lea    0x20(%rsp),%r12
jmp    1305 <cap_getint+0x175>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
mov    %rbp,%rsi
mov    %r12,%rdx
call   1070 <strtok_r@plt>
mov    %rax,%r15
test   %rax,%rax
je     1371 <cap_getint+0x1e1>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1321 <cap_getint+0x191>
cmpb   $0x23,0x2(%r15)
je     1357 <cap_getint+0x1c7>
mov    %r15,%rdi
mov    %r13,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    12f0 <cap_getint+0x160>
add    $0x3,%r15
mov    0x18(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    (%rsp),%rcx
call   1050 <cap_getint@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     12f0 <cap_getint+0x160>
jmp    136e <cap_getint+0x1de>
add    $0x3,%r15
lea    0xca4(%rip),%rsi
mov    %r15,%rdi
mov    (%rsp),%rdx
call   1090 <sscanf@plt>
mov    %eax,%r14d
addl   $0xffffffff,0x2cf4(%rip)
mov    0x8(%rsp),%rdi
call   1040 <fclose@plt>
mov    %r14d,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@cap_getint.rlev = internal global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"|\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c"tc=\00"
define i32 @cap_getint(i8* %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca [2048 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32* %3, i32** %9
store i32 -1, i32* %15
%17 = load i32, i32* @cap_getint.rlev
%18 = add nsw i32 %17, 1
store i32 %18, i32* @cap_getint.rlev
%19 = icmp sgt i32 %18, 32
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 -1, i32* %5
br label %103
21: ; preds = %4
%22 = load i8*, i8** %6
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %10
%24 = load i32*, i32** %10
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %21
br label %93
27: ; preds = %21
br label %28
28: ; preds = %91, %27
%29 = load i32*, i32** %10
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %16, i64 0, i64 0
%31 = call i64 @cap_getent(i32* %29, i8* %30, i32 2048)
%32 = icmp sgt i64 %31, 0
br i1 %32, label %33, label %92
33: ; preds = %28
%34 = getelementptr inbounds [2048 x i8], [2048 x i8]* %16, i64 0, i64 0
%35 = call i8* @strchr(i8* %34, i8 signext 58)
store i8* %35, i8** %12
%36 = load i8*, i8** %12
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %12
store i8 0, i8* %36
%38 = getelementptr inbounds [2048 x i8], [2048 x i8]* %16, i64 0, i64 0
%39 = call i8* @strtok_r(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %13)
store i8* %39, i8** %11
br label %40
40: ; preds = %89, %33
%41 = load i8*, i8** %11
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %91
43: ; preds = %40
%44 = load i8*, i8** %11
%45 = load i8*, i8** %7
%46 = call i64 @strcmp(i8* %44, i8* %45)
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %89
48: ; preds = %43
%49 = load i8*, i8** %12
%50 = call i8* @strtok_r(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %14)
store i8* %50, i8** %12
br label %51
51: ; preds = %86, %48
%52 = load i8*, i8** %12
%53 = icmp ne i8* %52, null
br i1 %53, label %54, label %88
54: ; preds = %51
%55 = load i8*, i8** %12
%56 = load i8*, i8** %8
%57 = call i64 @strncmp(i8* %55, i8* %56, i32 2)
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %70
59: ; preds = %54
%60 = load i8*, i8** %12
%61 = getelementptr inbounds i8, i8* %60, i64 2
%62 = load i8, i8* %61
%63 = sext i8 %62 to i32
%64 = icmp eq i32 %63, 35
br i1 %64, label %65, label %70
65: ; preds = %59
%66 = load i8*, i8** %12
%67 = getelementptr inbounds i8, i8* %66, i64 3
%68 = load i32*, i32** %9
%69 = call i32 @sscanf(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %68)
store i32 %69, i32* %15
br label %93
70: ; preds = %59, %54
%71 = load i8*, i8** %12
%72 = call i64 @strncmp(i8* %71, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %85
74: ; preds = %70
%75 = load i8*, i8** %6
%76 = load i8*, i8** %12
%77 = getelementptr inbounds i8, i8* %76, i64 3
%78 = load i8*, i8** %8
%79 = load i32*, i32** %9
%80 = call i32 @cap_getint(i8* %75, i8* %77, i8* %78, i32* %79)
store i32 %80, i32* %15
%81 = load i32, i32* %15
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %74
br label %93
84: ; preds = %74
br label %85
85: ; preds = %84, %70
br label %86
86: ; preds = %85
%87 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %14)
store i8* %87, i8** %12
br label %51
88: ; preds = %51
br label %93
89: ; preds = %43
%90 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %13)
store i8* %90, i8** %11
br label %40
91: ; preds = %40
br label %28
92: ; preds = %28
br label %93
93: ; preds = %92, %88, %83, %65, %26
%94 = load i32, i32* @cap_getint.rlev
%95 = add nsw i32 %94, -1
store i32 %95, i32* @cap_getint.rlev
%96 = load i32*, i32** %10
%97 = icmp ne i32* %96, null
br i1 %97, label %98, label %101
98: ; preds = %93
%99 = load i32*, i32** %10
%100 = call i32 @fclose(i32* %99)
br label %101
101: ; preds = %98, %93
%102 = load i32, i32* %15
store i32 %102, i32* %5
br label %103
103: ; preds = %101, %20
%104 = load i32, i32* %5
ret i32 %104
}

LLVM IR (-O2):
@cap_getint.rlev = internal unnamed_addr global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"|\00"
@.str.2 = [2 x i8] c":\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c"tc=\00"
define i32 @cap_getint(i8* nocapture %0, i8* %1, i8* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [2048 x i8]
%8 = bitcast i8** %5 to i8*
%9 = bitcast i8** %6 to i8*
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%11 = load i32, i32* @cap_getint.rlev
%12 = add nsw i32 %11, 1
store i32 %12, i32* @cap_getint.rlev
%13 = icmp sgt i32 %11, 31
br i1 %13, label %69, label %14
14: ; preds = %4
%15 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %20, label %17
17: ; preds = %14
%18 = call i64 @cap_getent(i32* %15, i8* %10, i32 2048)
%19 = icmp sgt i64 %18, 0
br i1 %19, label %26, label %64
20: ; preds = %14
%21 = load i32, i32* @cap_getint.rlev
%22 = add nsw i32 %21, -1
store i32 %22, i32* @cap_getint.rlev
br label %69
23: ; preds = %61, %26
%24 = call i64 @cap_getent(i32* %15, i8* %10, i32 2048)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %26, label %64
26: ; preds = %17, %23
%27 = call i8* @strchr(i8* %10, i8 signext 58)
store i8 0, i8* %27
%28 = call i8* @strtok_r(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %5)
%29 = icmp eq i8* %28, null
br i1 %29, label %23, label %30
30: ; preds = %26, %61
%31 = phi i8* [ %62, %61 ], [ %28, %26 ]
%32 = call i64 @strcmp(i8* %31, i8* %1)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %61
34: ; preds = %30
%35 = getelementptr inbounds i8, i8* %27, i64 1
%36 = call i8* @strtok_r(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %6)
%37 = icmp eq i8* %36, null
br i1 %37, label %64, label %38
38: ; preds = %34, %57
%39 = phi i32 [ %58, %57 ], [ -1, %34 ]
%40 = phi i8* [ %59, %57 ], [ %36, %34 ]
%41 = call i64 @strncmp(i8* %40, i8* %2, i32 2)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %50
43: ; preds = %38
%44 = getelementptr inbounds i8, i8* %40, i64 2
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 35
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = getelementptr inbounds i8, i8* %40, i64 3
%49 = call i32 @sscanf(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
br label %64
50: ; preds = %43, %38
%51 = call i64 @strncmp(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 3)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = getelementptr inbounds i8, i8* %40, i64 3
%55 = call i32 @cap_getint(i8* %0, i8* %54, i8* %2, i32* %3)
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %64
57: ; preds = %50, %53
%58 = phi i32 [ 0, %53 ], [ %39, %50 ]
%59 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %6)
%60 = icmp eq i8* %59, null
br i1 %60, label %64, label %38
61: ; preds = %30
%62 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %5)
%63 = icmp eq i8* %62, null
br i1 %63, label %23, label %30
64: ; preds = %23, %57, %53, %47, %34, %17
%65 = phi i32 [ %49, %47 ], [ -1, %34 ], [ -1, %17 ], [ %55, %53 ], [ %58, %57 ], [ -1, %23 ]
%66 = load i32, i32* @cap_getint.rlev
%67 = add nsw i32 %66, -1
store i32 %67, i32* @cap_getint.rlev
%68 = call i32 @fclose(i32* %15)
br label %69
69: ; preds = %20, %64, %4
%70 = phi i32 [ -1, %4 ], [ %65, %64 ], [ -1, %20 ]
ret i32 %70
}