#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 */
struct smack_accesses {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int dup(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int smack_accesses_add(struct smack_accesses *, char const *, char const *,
                       char const *);
int smack_accesses_add_modify(struct smack_accesses *, char const *,
                              char const *, char const *, char const *);
scalar_t__ strcmp(char *, char *);
char *strtok_r(char *, char *, char **);
int smack_accesses_add_from_file(struct smack_accesses *accesses, int fd) {
  FILE *file = NULL;
  char *buf = NULL;
  size_t buf_len = 0;
  char *ptr;
  const char *subject, *object, *access, *access2;
  int newfd;
  int ret;
  newfd = dup(fd);
  if (newfd == -1)
    return -1;
  file = fdopen(newfd, "r");
  if (file == NULL) {
    close(newfd);
    return -1;
  }
  while (getline(&buf, &buf_len, file) >= 0) {
    if (strcmp(buf, "\n") == 0)
      continue;
    subject = strtok_r(buf, " \t\n", &ptr);
    object = strtok_r(NULL, " \t\n", &ptr);
    access = strtok_r(NULL, " \t\n", &ptr);
    access2 = strtok_r(NULL, " \t\n", &ptr);
    if (subject == NULL || object == NULL || access == NULL ||
        strtok_r(NULL, " \t\n", &ptr) != NULL)
      goto err_out;
    if (access2 == NULL)
      ret = smack_accesses_add(accesses, subject, object, access);
    else
      ret =
          smack_accesses_add_modify(accesses, subject, object, access, access2);
    if (ret)
      goto err_out;
  }
  if (ferror(file))
    goto err_out;
  free(buf);
  fclose(file);
  return 0;
err_out:
  free(buf);
  fclose(file);
  return -1;
}


x86 assembly (clang, -O0):
<smack_accesses_add_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <dup@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    11f8 <smack_accesses_add_from_file+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b4 <smack_accesses_add_from_file+0x204>
mov    -0x5c(%rbp),%edi
lea    0xdfe(%rip),%rsi
call   10c0 <fdopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    122a <smack_accesses_add_from_file+0x7a>
mov    -0x5c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b4 <smack_accesses_add_from_file+0x204>
jmp    122f <smack_accesses_add_from_file+0x7f>
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10d0 <getline@plt>
cmp    $0x0,%rax
jl     1365 <smack_accesses_add_from_file+0x1b5>
mov    -0x28(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1269 <smack_accesses_add_from_file+0xb9>
jmp    122f <smack_accesses_add_from_file+0x7f>
mov    -0x28(%rbp),%rdi
lea    0xd8e(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1090 <strtok_r@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd76(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1090 <strtok_r@plt>
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd5e(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1090 <strtok_r@plt>
mov    %rax,-0x50(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd46(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1090 <strtok_r@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1308 <smack_accesses_add_from_file+0x158>
cmpq   $0x0,-0x48(%rbp)
je     1308 <smack_accesses_add_from_file+0x158>
cmpq   $0x0,-0x50(%rbp)
je     1308 <smack_accesses_add_from_file+0x158>
xor    %eax,%eax
mov    %eax,%edi
lea    0xd0d(%rip),%rsi
lea    -0x38(%rbp),%rdx
call   1090 <strtok_r@plt>
cmp    $0x0,%rax
je     130d <smack_accesses_add_from_file+0x15d>
jmp    139b <smack_accesses_add_from_file+0x1eb>
cmpq   $0x0,-0x58(%rbp)
jne    1335 <smack_accesses_add_from_file+0x185>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rcx
call   10b0 <smack_accesses_add@plt>
mov    %eax,-0x60(%rbp)
jmp    1351 <smack_accesses_add_from_file+0x1a1>
mov    -0x10(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    -0x58(%rbp),%r8
call   1070 <smack_accesses_add_modify@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0x0,-0x60(%rbp)
je     1360 <smack_accesses_add_from_file+0x1b0>
jmp    139b <smack_accesses_add_from_file+0x1eb>
jmp    122f <smack_accesses_add_from_file+0x7f>
mov    -0x20(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     137d <smack_accesses_add_from_file+0x1cd>
jmp    139b <smack_accesses_add_from_file+0x1eb>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    13b4 <smack_accesses_add_from_file+0x204>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smack_accesses_add_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,0x10(%rsp)
movq   $0x0,(%rsp)
movq   $0x0,0x18(%rsp)
mov    %esi,%edi
call   1060 <dup@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     1371 <smack_accesses_add_from_file+0x1c1>
mov    %eax,%ebx
lea    0xe0d(%rip),%rsi
mov    %eax,%edi
call   10c0 <fdopen@plt>
test   %rax,%rax
je     1352 <smack_accesses_add_from_file+0x1a2>
mov    %rax,%rbp
mov    %rsp,%rdi
lea    0x18(%rsp),%rsi
mov    %rax,%rdx
call   10d0 <getline@plt>
test   %rax,%rax
mov    %rbp,0x8(%rsp)
js     132a <smack_accesses_add_from_file+0x17a>
lea    0xdd7(%rip),%r14
lea    0x20(%rsp),%r12
jmp    1270 <smack_accesses_add_from_file+0xc0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rsp),%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %rbx,%r8
call   1070 <smack_accesses_add_modify@plt>
test   %eax,%eax
je     130c <smack_accesses_add_from_file+0x15c>
jmp    1337 <smack_accesses_add_from_file+0x187>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp),%rdi
lea    0xd89(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     130c <smack_accesses_add_from_file+0x15c>
mov    (%rsp),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1090 <strtok_r@plt>
mov    %rax,%r13
xor    %edi,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   1090 <strtok_r@plt>
mov    %rax,%r15
xor    %edi,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   1090 <strtok_r@plt>
mov    %rax,%rbp
xor    %edi,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   1090 <strtok_r@plt>
test   %r13,%r13
je     1337 <smack_accesses_add_from_file+0x187>
test   %r15,%r15
je     1337 <smack_accesses_add_from_file+0x187>
test   %rbp,%rbp
je     1337 <smack_accesses_add_from_file+0x187>
mov    %rax,%rbx
xor    %edi,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   1090 <strtok_r@plt>
test   %rax,%rax
jne    1337 <smack_accesses_add_from_file+0x187>
test   %rbx,%rbx
jne    1240 <smack_accesses_add_from_file+0x90>
mov    0x10(%rsp),%rdi
mov    %r13,%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
call   10b0 <smack_accesses_add@plt>
test   %eax,%eax
jne    1337 <smack_accesses_add_from_file+0x187>
mov    %rsp,%rdi
lea    0x18(%rsp),%rsi
mov    0x8(%rsp),%rbp
mov    %rbp,%rdx
call   10d0 <getline@plt>
test   %rax,%rax
jns    1270 <smack_accesses_add_from_file+0xc0>
mov    %rbp,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     135b <smack_accesses_add_from_file+0x1ab>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
mov    $0xffffffff,%r14d
jmp    1371 <smack_accesses_add_from_file+0x1c1>
mov    %ebx,%edi
call   1080 <close@plt>
jmp    1371 <smack_accesses_add_from_file+0x1c1>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1050 <fclose@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.smack_accesses = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [4 x i8] c" \09\0A\00"
define i32 @smack_accesses_add_from_file(%struct.smack_accesses* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.smack_accesses*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store %struct.smack_accesses* %0, %struct.smack_accesses** %4
store i32 %1, i32* %5
store i32* null, i32** %6
store i8* null, i8** %7
store i64 0, i64* %8
%16 = load i32, i32* %5
%17 = call i32 @dup(i32 %16)
store i32 %17, i32* %14
%18 = load i32, i32* %14
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %2
store i32 -1, i32* %3
br label %93
21: ; preds = %2
%22 = load i32, i32* %14
%23 = call i32* @fdopen(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %6
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* %14
%28 = call i32 @close(i32 %27)
store i32 -1, i32* %3
br label %93
29: ; preds = %21
br label %30
30: ; preds = %77, %38, %29
%31 = load i32*, i32** %6
%32 = call i64 @getline(i8** %7, i64* %8, i32* %31)
%33 = icmp sge i64 %32, 0
br i1 %33, label %34, label %78
34: ; preds = %30
%35 = load i8*, i8** %7
%36 = call i64 @strcmp(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
br label %30
39: ; preds = %34
%40 = load i8*, i8** %7
%41 = call i8* @strtok_r(i8* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %9)
store i8* %41, i8** %10
%42 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %9)
store i8* %42, i8** %11
%43 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %9)
store i8* %43, i8** %12
%44 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %9)
store i8* %44, i8** %13
%45 = load i8*, i8** %10
%46 = icmp eq i8* %45, null
br i1 %46, label %56, label %47
47: ; preds = %39
%48 = load i8*, i8** %11
%49 = icmp eq i8* %48, null
br i1 %49, label %56, label %50
50: ; preds = %47
%51 = load i8*, i8** %12
%52 = icmp eq i8* %51, null
br i1 %52, label %56, label %53
53: ; preds = %50
%54 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %9)
%55 = icmp ne i8* %54, null
br i1 %55, label %56, label %57
56: ; preds = %53, %50, %47, %39
br label %88
57: ; preds = %53
%58 = load i8*, i8** %13
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %66
60: ; preds = %57
%61 = load %struct.smack_accesses*, %struct.smack_accesses** %4
%62 = load i8*, i8** %10
%63 = load i8*, i8** %11
%64 = load i8*, i8** %12
%65 = call i32 @smack_accesses_add(%struct.smack_accesses* %61, i8* %62, i8* %63, i8* %64)
store i32 %65, i32* %15
br label %73
66: ; preds = %57
%67 = load %struct.smack_accesses*, %struct.smack_accesses** %4
%68 = load i8*, i8** %10
%69 = load i8*, i8** %11
%70 = load i8*, i8** %12
%71 = load i8*, i8** %13
%72 = call i32 @smack_accesses_add_modify(%struct.smack_accesses* %67, i8* %68, i8* %69, i8* %70, i8* %71)
store i32 %72, i32* %15
br label %73
73: ; preds = %66, %60
%74 = load i32, i32* %15
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %73
br label %88
77: ; preds = %73
br label %30
78: ; preds = %30
%79 = load i32*, i32** %6
%80 = call i64 @ferror(i32* %79)
%81 = icmp ne i64 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %78
br label %88
83: ; preds = %78
%84 = load i8*, i8** %7
%85 = call i32 @free(i8* %84)
%86 = load i32*, i32** %6
%87 = call i32 @fclose(i32* %86)
store i32 0, i32* %3
br label %93
88: ; preds = %82, %76, %56
%89 = load i8*, i8** %7
%90 = call i32 @free(i8* %89)
%91 = load i32*, i32** %6
%92 = call i32 @fclose(i32* %91)
store i32 -1, i32* %3
br label %93
93: ; preds = %88, %83, %26, %20
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
%struct.smack_accesses = type { i32 }
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [4 x i8] c" \09\0A\00"
define i32 @smack_accesses_add_from_file(%struct.smack_accesses* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%8 = bitcast i8** %5 to i8*
%9 = tail call i32 @dup(i32 %1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %60, label %11
11: ; preds = %2
%12 = tail call i32* @fdopen(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = call i64 @getline(i8** %3, i64* %4, i32* %12)
%16 = icmp sgt i64 %15, -1
br i1 %16, label %19, label %49
17: ; preds = %11
%18 = tail call i32 @close(i32 %9)
br label %60
19: ; preds = %14, %23
%20 = load i8*, i8** %3
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19, %46
%24 = call i64 @getline(i8** %3, i64* %4, i32* %12)
%25 = icmp sgt i64 %24, -1
br i1 %25, label %19, label %49
26: ; preds = %19
%27 = load i8*, i8** %3
%28 = call i8* @strtok_r(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%29 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%30 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%31 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%32 = icmp eq i8* %28, null
%33 = icmp eq i8* %29, null
%34 = select i1 %32, i1 true, i1 %33
%35 = icmp eq i8* %30, null
%36 = select i1 %34, i1 true, i1 %35
br i1 %36, label %56, label %37
37: ; preds = %26
%38 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %56
40: ; preds = %37
%41 = icmp eq i8* %31, null
br i1 %41, label %42, label %44
42: ; preds = %40
%43 = call i32 @smack_accesses_add(%struct.smack_accesses* %0, i8* %28, i8* %29, i8* %30)
br label %46
44: ; preds = %40
%45 = call i32 @smack_accesses_add_modify(%struct.smack_accesses* %0, i8* %28, i8* %29, i8* %30, i8* %31)
br label %46
46: ; preds = %44, %42
%47 = phi i32 [ %43, %42 ], [ %45, %44 ]
%48 = icmp eq i32 %47, 0
br i1 %48, label %23, label %56
49: ; preds = %23, %14
%50 = call i64 @ferror(i32* %12)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = load i8*, i8** %3
%54 = call i32 @free(i8* %53)
%55 = call i32 @fclose(i32* %12)
br label %60
56: ; preds = %46, %26, %37, %49
%57 = load i8*, i8** %3
%58 = call i32 @free(i8* %57)
%59 = call i32 @fclose(i32* %12)
br label %60
60: ; preds = %2, %56, %52, %17
%61 = phi i32 [ -1, %17 ], [ -1, %56 ], [ 0, %52 ], [ -1, %2 ]
ret i32 %61
}