#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 EOF;
int MAXPATHLEN;
int /*<<< orphan*/ addsym(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ findsym(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *popfp();
int /*<<< orphan*/ pushfp(int /*<<< orphan*/ *);
char *strchr(char *, char);
int tokenscpp(char *, char *);
FILE *fincludegets(char *buf, int size, FILE *fp) {
  char name[MAXPATHLEN];
  FILE *nfp = NULL;
  char *p;
  int ch;
  if (fp == NULL)
    return (NULL);
  if (fgets(buf, size, fp) == NULL) {
    *buf = '\0';
    fclose(fp);
    fp = popfp();
    return (fp);
  }
  if ((p = strchr(buf, '\n')) != NULL)
    *p = '\0';
  else {
    while ((ch = fgetc(fp)) != '\n' && ch != EOF)
      ;
    if (ch == EOF) {
      *buf = '\0';
      fclose(fp);
      fp = popfp();
      return (fp);
    }
  }
  switch (tokenscpp(buf, name)) {
  case 0:
    *buf = '\0';
    if ((nfp = fopen(name, "r")) != NULL) {
      pushfp(fp);
      fp = nfp;
    }
    break;
  case 1:
    addsym(name);
    break;
  case 2:
    if (findsym(name)) {
      fclose(fp);
      fp = popfp();
      *buf = '\0';
    }
    break;
  case 3:
    *buf = '\0';
    break;
  default:
    break;
  }
  return (fp);
}


x86 assembly (clang, -O0):
<fincludegets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1206 <fincludegets+0x66>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13d0 <fincludegets+0x230>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1090 <fgets@plt>
cmp    $0x0,%rax
jne    124f <fincludegets+0xaf>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   10a0 <popfp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13d0 <fincludegets+0x230>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
je     1277 <fincludegets+0xd7>
mov    -0x40(%rbp),%rax
movb   $0x0,(%rax)
jmp    1305 <fincludegets+0x165>
jmp    127c <fincludegets+0xdc>
mov    -0x20(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x44(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x51(%rbp)
je     12aa <fincludegets+0x10a>
mov    -0x44(%rbp),%eax
mov    0x2d46(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
test   $0x1,%al
jne    12ba <fincludegets+0x11a>
jmp    12bf <fincludegets+0x11f>
jmp    127c <fincludegets+0xdc>
mov    -0x44(%rbp),%eax
mov    0x2d1f(%rip),%rcx
cmp    (%rcx),%eax
jne    1300 <fincludegets+0x160>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   10a0 <popfp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    13d0 <fincludegets+0x230>
jmp    1305 <fincludegets+0x165>
mov    -0x50(%rbp),%rsi
mov    -0x10(%rbp),%rdi
call   1030 <tokenscpp@plt>
mov    %eax,%ecx
mov    %rcx,-0x60(%rbp)
sub    $0x3,%eax
ja     13bc <fincludegets+0x21c>
mov    -0x60(%rbp),%rax
lea    0xcd4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
lea    0xcc9(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     136b <fincludegets+0x1cb>
mov    -0x20(%rbp),%rdi
call   1050 <pushfp@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    13c1 <fincludegets+0x221>
mov    -0x50(%rbp),%rdi
call   1070 <addsym@plt>
jmp    13c1 <fincludegets+0x221>
mov    -0x50(%rbp),%rdi
call   10b0 <findsym@plt>
cmp    $0x0,%eax
je     13ab <fincludegets+0x20b>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x0,%al
call   10a0 <popfp@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    13c1 <fincludegets+0x221>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    13c1 <fincludegets+0x221>
jmp    13c1 <fincludegets+0x221>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fincludegets>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
test   %rdx,%rdx
je     11f1 <fincludegets+0x51>
mov    %rdx,%r12
mov    %rdi,%r14
call   1090 <fgets@plt>
test   %rax,%rax
je     1217 <fincludegets+0x77>
mov    %r14,%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11f9 <fincludegets+0x59>
movb   $0x0,(%rax)
jmp    1236 <fincludegets+0x96>
xor    %r12d,%r12d
jmp    12ac <fincludegets+0x10c>
mov    0x2de8(%rip),%rbx
mov    %r12,%rdi
call   1080 <fgetc@plt>
mov    (%rbx),%ecx
cmp    $0xa,%eax
je     1213 <fincludegets+0x73>
cmp    %ecx,%eax
jne    1200 <fincludegets+0x60>
cmp    %ecx,%eax
jne    1236 <fincludegets+0x96>
movb   $0x0,(%r14)
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    10a0 <popfp@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <tokenscpp@plt>
cmp    $0x3,%eax
ja     12ac <fincludegets+0x10c>
mov    %eax,%eax
lea    0xdb1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x0,(%r14)
lea    0xdad(%rip),%rsi
mov    %r15,%rdi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12ac <fincludegets+0x10c>
mov    %rax,%r14
mov    %r12,%rdi
call   1050 <pushfp@plt>
mov    %r14,%r12
jmp    12ac <fincludegets+0x10c>
mov    %r15,%rdi
call   1070 <addsym@plt>
jmp    12ac <fincludegets+0x10c>
mov    %r15,%rdi
call   10b0 <findsym@plt>
test   %eax,%eax
je     12ac <fincludegets+0x10c>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
call   10a0 <popfp@plt>
mov    %rax,%r12
movb   $0x0,(%r14)
mov    %r12,%rax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@EOF = global i32 0
@.str = [2 x i8] c"r\00"
define i32* @fincludegets(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
%14 = load i32, i32* @MAXPATHLEN
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %8
%17 = alloca i8, i64 %15
store i64 %15, i64* %9
store i32* null, i32** %10
%18 = load i32*, i32** %7
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %21
20: ; preds = %3
store i32* null, i32** %4
store i32 1, i32* %13
br label %90
21: ; preds = %3
%22 = load i8*, i8** %5
%23 = load i32, i32* %6
%24 = load i32*, i32** %7
%25 = call i32* @fgets(i8* %22, i32 %23, i32* %24)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %33
27: ; preds = %21
%28 = load i8*, i8** %5
store i8 0, i8* %28
%29 = load i32*, i32** %7
%30 = call i32 @fclose(i32* %29)
%31 = call i32* (...) @popfp()
store i32* %31, i32** %7
%32 = load i32*, i32** %7
store i32* %32, i32** %4
store i32 1, i32* %13
br label %90
33: ; preds = %21
%34 = load i8*, i8** %5
%35 = call i8* @strchr(i8* %34, i8 signext 10)
store i8* %35, i8** %11
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = load i8*, i8** %11
store i8 0, i8* %38
br label %62
39: ; preds = %33
br label %40
40: ; preds = %50, %39
%41 = load i32*, i32** %7
%42 = call i32 @fgetc(i32* %41)
store i32 %42, i32* %12
%43 = icmp ne i32 %42, 10
br i1 %43, label %44, label %48
44: ; preds = %40
%45 = load i32, i32* %12
%46 = load i32, i32* @EOF
%47 = icmp ne i32 %45, %46
br label %48
48: ; preds = %44, %40
%49 = phi i1 [ false, %40 ], [ %47, %44 ]
br i1 %49, label %50, label %51
50: ; preds = %48
br label %40
51: ; preds = %48
%52 = load i32, i32* %12
%53 = load i32, i32* @EOF
%54 = icmp eq i32 %52, %53
br i1 %54, label %55, label %61
55: ; preds = %51
%56 = load i8*, i8** %5
store i8 0, i8* %56
%57 = load i32*, i32** %7
%58 = call i32 @fclose(i32* %57)
%59 = call i32* (...) @popfp()
store i32* %59, i32** %7
%60 = load i32*, i32** %7
store i32* %60, i32** %4
store i32 1, i32* %13
br label %90
61: ; preds = %51
br label %62
62: ; preds = %61, %37
%63 = load i8*, i8** %5
%64 = call i32 @tokenscpp(i8* %63, i8* %17)
switch i32 %64, label %87 [
i32 0, label %65
i32 1, label %74
i32 2, label %76
i32 3, label %85
]
65: ; preds = %62
%66 = load i8*, i8** %5
store i8 0, i8* %66
%67 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %67, i32** %10
%68 = icmp ne i32* %67, null
br i1 %68, label %69, label %73
69: ; preds = %65
%70 = load i32*, i32** %7
%71 = call i32 @pushfp(i32* %70)
%72 = load i32*, i32** %10
store i32* %72, i32** %7
br label %73
73: ; preds = %69, %65
br label %88
74: ; preds = %62
%75 = call i32 @addsym(i8* %17)
br label %88
76: ; preds = %62
%77 = call i32 @findsym(i8* %17)
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %84
79: ; preds = %76
%80 = load i32*, i32** %7
%81 = call i32 @fclose(i32* %80)
%82 = call i32* (...) @popfp()
store i32* %82, i32** %7
%83 = load i8*, i8** %5
store i8 0, i8* %83
br label %84
84: ; preds = %79, %76
br label %88
85: ; preds = %62
%86 = load i8*, i8** %5
store i8 0, i8* %86
br label %88
87: ; preds = %62
br label %88
88: ; preds = %87, %85, %84, %74, %73
%89 = load i32*, i32** %7
store i32* %89, i32** %4
store i32 1, i32* %13
br label %90
90: ; preds = %88, %55, %27, %20
%91 = load i8*, i8** %8
%92 = load i32*, i32** %4
ret i32* %92
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@EOF = global i32 0
@.str = [2 x i8] c"r\00"
define i32* @fincludegets(i8* %0, i32 %1, i32* %2) {
%4 = load i32, i32* @MAXPATHLEN
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = icmp eq i32* %2, null
br i1 %7, label %45, label %8
8: ; preds = %3
%9 = tail call i32* @fgets(i8* %0, i32 %1, i32* %2)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
store i8 0, i8* %0
%12 = tail call i32 @fclose(i32* %2)
%13 = tail call i32* (...) @popfp()
br label %45
14: ; preds = %8
%15 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%16 = icmp eq i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store i8 0, i8* %15
br label %29
18: ; preds = %14, %18
%19 = tail call i32 @fgetc(i32* %2)
%20 = icmp ne i32 %19, 10
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %19, %21
%23 = select i1 %20, i1 %22, i1 false
br i1 %23, label %18, label %24
24: ; preds = %18
%25 = icmp eq i32 %19, %21
br i1 %25, label %26, label %29
26: ; preds = %24
store i8 0, i8* %0
%27 = tail call i32 @fclose(i32* %2)
%28 = tail call i32* (...) @popfp()
br label %45
29: ; preds = %24, %17
%30 = call i32 @tokenscpp(i8* %0, i8* %6)
switch i32 %30, label %45 [
i32 0, label %31
i32 1, label %36
i32 2, label %38
i32 3, label %44
]
31: ; preds = %29
store i8 0, i8* %0
%32 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %45, label %34
34: ; preds = %31
%35 = call i32 @pushfp(i32* %2)
br label %45
36: ; preds = %29
%37 = call i32 @addsym(i8* %6)
br label %45
38: ; preds = %29
%39 = call i32 @findsym(i8* %6)
%40 = icmp eq i32 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %38
%42 = call i32 @fclose(i32* %2)
%43 = call i32* (...) @popfp()
store i8 0, i8* %0
br label %45
44: ; preds = %29
store i8 0, i8* %0
br label %45
45: ; preds = %36, %44, %34, %31, %41, %38, %29, %3, %26, %11
%46 = phi i32* [ %13, %11 ], [ %28, %26 ], [ null, %3 ], [ %2, %29 ], [ %2, %44 ], [ %43, %41 ], [ %2, %38 ], [ %2, %36 ], [ %32, %34 ], [ %2, %31 ]
ret i32* %46
}