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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, int *);
int read_pseudo_def(struct pseudo **, char *);
char *realloc(char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int read_pseudo_file(struct pseudo **pseudo, char *filename) {
  FILE *fd;
  char *line = NULL;
  int size = 0;
  int res = 1;
  fd = fopen(filename, "r");
  if (fd == NULL) {
    do {
      fprintf(stderr, "Could not open pseudo device file \"%s\" because %s\n",
              filename, strerror(errno));
    } while (0);
    return 0;
  }
  while (1) {
    int total = 0;
    while (1) {
      int n, err;
      if (total + 2048 > size) {
        line = realloc(line, size += 2048);
        if (line == NULL) {
          do {
            fprintf(stderr, "No space in read_pseudo_file\n");
          } while (0);
          return 0;
        }
      }
      err = fscanf(fd, "%2047[^\n]%n\n", line + total, &n);
      if (err <= 0)
        goto done;
      if (line[total] == '#')
        continue;
      if (line[total + n - 1] != '\\')
        break;
      total += n - 1;
    }
    res = read_pseudo_def(pseudo, line);
    if (res == 0)
      break;
  }
done:
  fclose(fd);
  free(line);
  return res;
}


x86 assembly (clang, -O0):
<read_pseudo_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1210 <read_pseudo_file+0x90>
jmp    11ca <read_pseudo_file+0x4a>
mov    0x2e0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xe05(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    133d <read_pseudo_file+0x1bd>
jmp    1215 <read_pseudo_file+0x95>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x800,%eax
cmp    -0x2c(%rbp),%eax
jle    127e <read_pseudo_file+0xfe>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0x800,%esi
mov    %esi,-0x2c(%rbp)
call   1070 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1279 <read_pseudo_file+0xf9>
jmp    1256 <read_pseudo_file+0xd6>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    133d <read_pseudo_file+0x1bd>
jmp    127e <read_pseudo_file+0xfe>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
movslq -0x34(%rbp),%rax
add    %rax,%rdx
lea    0xdbf(%rip),%rsi
lea    -0x38(%rbp),%rcx
call   1050 <fscanf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jg     12af <read_pseudo_file+0x12f>
jmp    1325 <read_pseudo_file+0x1a5>
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x23,%eax
jne    12c9 <read_pseudo_file+0x149>
jmp    121c <read_pseudo_file+0x9c>
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    -0x38(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5c,%eax
je     12eb <read_pseudo_file+0x16b>
jmp    12fc <read_pseudo_file+0x17c>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    121c <read_pseudo_file+0x9c>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <read_pseudo_def@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jne    131b <read_pseudo_file+0x19b>
jmp    1320 <read_pseudo_file+0x1a0>
jmp    1215 <read_pseudo_file+0x95>
jmp    1325 <read_pseudo_file+0x1a5>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pseudo_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %rdi,0x10(%rsp)
lea    0xe63(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1295 <read_pseudo_file+0x115>
mov    %rax,%r15
movl   $0x1,0x8(%rsp)
lea    0xc(%rsp),%r12
xor    %ebp,%ebp
xor    %r14d,%r14d
jmp    11dd <read_pseudo_file+0x5d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0xa,%ebx
test   %ebx,%ebx
jne    1283 <read_pseudo_file+0x103>
xor    %r13d,%r13d
lea    0x800(%r13),%eax
cmp    %r14d,%eax
jle    1206 <read_pseudo_file+0x86>
add    $0x800,%r14d
mov    %rbp,%rdi
mov    %r14d,%esi
call   1070 <realloc@plt>
test   %rax,%rax
je     1260 <read_pseudo_file+0xe0>
mov    %rax,%rbp
movslq %r13d,%rbx
add    %rbp,%rbx
mov    %r15,%rdi
lea    0xe3d(%rip),%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1050 <fscanf@plt>
test   %eax,%eax
jle    11d0 <read_pseudo_file+0x50>
cmpb   $0x23,(%rbx)
je     11e0 <read_pseudo_file+0x60>
mov    0xc(%rsp),%eax
add    %eax,%r13d
add    $0xffffffff,%r13d
movslq %r13d,%rax
cmpb   $0x5c,0x0(%rbp,%rax,1)
je     11e0 <read_pseudo_file+0x60>
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
call   1080 <read_pseudo_def@plt>
xor    %ebx,%ebx
mov    %eax,0x8(%rsp)
test   %eax,%eax
jne    11d5 <read_pseudo_file+0x55>
jmp    12cc <read_pseudo_file+0x14c>
nopl   0x0(%rax)
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xdc5(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%ebx
xor    %ebp,%ebp
jmp    11d5 <read_pseudo_file+0x55>
cmp    $0xa,%ebx
je     12c8 <read_pseudo_file+0x148>
cmp    $0x5,%ebx
mov    0x8(%rsp),%ebx
je     12cc <read_pseudo_file+0x14c>
xor    %ebx,%ebx
jmp    12dc <read_pseudo_file+0x15c>
mov    0x2d44(%rip),%rax
mov    (%rax),%r14d
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd4e(%rip),%rsi
xor    %ebx,%ebx
mov    %r14d,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12dc <read_pseudo_file+0x15c>
mov    0x8(%rsp),%ebx
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pseudo = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [51 x i8] c"Could not open pseudo device file \22%s\22 because %s\0A\00"
@errno = global i32 0
@.str.2 = [30 x i8] c"No space in read_pseudo_file\0A\00"
@.str.3 = [13 x i8] c"%2047[^\0A]%n\0A\00"
define i32 @read_pseudo_file(%struct.pseudo** %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.pseudo**
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store %struct.pseudo** %0, %struct.pseudo*** %4
store i8* %1, i8** %5
store i8* null, i8** %7
store i32 0, i32* %8
store i32 1, i32* %9
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %25
17: ; preds = %2
br label %18
18: ; preds = %17
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %5
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %22)
br label %24
24: ; preds = %18
store i32 0, i32* %3
br label %96
25: ; preds = %2
br label %26
26: ; preds = %25, %88
store i32 0, i32* %10
br label %27
27: ; preds = %26, %63, %76
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 2048
%30 = load i32, i32* %8
%31 = icmp sgt i32 %29, %30
br i1 %31, label %32, label %45
32: ; preds = %27
%33 = load i8*, i8** %7
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 2048
store i32 %35, i32* %8
%36 = call i8* @realloc(i8* %33, i32 %35)
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %44
39: ; preds = %32
br label %40
40: ; preds = %39
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %40
store i32 0, i32* %3
br label %96
44: ; preds = %32
br label %45
45: ; preds = %44, %27
%46 = load i32*, i32** %6
%47 = load i8*, i8** %7
%48 = load i32, i32* %10
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
%51 = call i32 @fscanf(i32* %46, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %50, i32* %11)
store i32 %51, i32* %12
%52 = load i32, i32* %12
%53 = icmp sle i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %45
br label %90
55: ; preds = %45
%56 = load i8*, i8** %7
%57 = load i32, i32* %10
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 35
br i1 %62, label %63, label %64
63: ; preds = %55
br label %27
64: ; preds = %55
%65 = load i8*, i8** %7
%66 = load i32, i32* %10
%67 = load i32, i32* %11
%68 = add nsw i32 %66, %67
%69 = sub nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %65, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp ne i32 %73, 92
br i1 %74, label %75, label %76
75: ; preds = %64
br label %81
76: ; preds = %64
%77 = load i32, i32* %11
%78 = sub nsw i32 %77, 1
%79 = load i32, i32* %10
%80 = add nsw i32 %79, %78
store i32 %80, i32* %10
br label %27
81: ; preds = %75
%82 = load %struct.pseudo**, %struct.pseudo*** %4
%83 = load i8*, i8** %7
%84 = call i32 @read_pseudo_def(%struct.pseudo** %82, i8* %83)
store i32 %84, i32* %9
%85 = load i32, i32* %9
%86 = icmp eq i32 %85, 0
br i1 %86, label %87, label %88
87: ; preds = %81
br label %89
88: ; preds = %81
br label %26
89: ; preds = %87
br label %90
90: ; preds = %89, %54
%91 = load i32*, i32** %6
%92 = call i32 @fclose(i32* %91)
%93 = load i8*, i8** %7
%94 = call i32 @free(i8* %93)
%95 = load i32, i32* %9
store i32 %95, i32* %3
br label %96
96: ; preds = %90, %43, %24
%97 = load i32, i32* %3
ret i32 %97
}

LLVM IR (-O2):
%struct.pseudo = type { i32 }
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [51 x i8] c"Could not open pseudo device file \22%s\22 because %s\0A\00"
@errno = global i32 0
@.str.2 = [30 x i8] c"No space in read_pseudo_file\0A\00"
@.str.3 = [13 x i8] c"%2047[^\0A]%n\0A\00"
define i32 @read_pseudo_file(%struct.pseudo** %0, i8* %1) {
%3 = alloca i32
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = bitcast i32* %3 to i8*
br label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %11)
br label %67
13: ; preds = %6, %57
%14 = phi i8* [ %59, %57 ], [ null, %6 ]
%15 = phi i32 [ %58, %57 ], [ 0, %6 ]
%16 = phi i32 [ %60, %57 ], [ 1, %6 ]
br label %17
17: ; preds = %52, %13
%18 = phi i8* [ %14, %13 ], [ %31, %52 ]
%19 = phi i32 [ %15, %13 ], [ %32, %52 ]
%20 = phi i32 [ 0, %13 ], [ %53, %52 ]
%21 = add nsw i32 %20, 2048
%22 = icmp sgt i32 %21, %19
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = add nsw i32 %19, 2048
%25 = call i8* @realloc(i8* %18, i32 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %48
30: ; preds = %23, %17
%31 = phi i8* [ %25, %23 ], [ %18, %17 ]
%32 = phi i32 [ %24, %23 ], [ %19, %17 ]
%33 = sext i32 %20 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %34, i32* %3)
%36 = icmp slt i32 %35, 1
br i1 %36, label %48, label %37
37: ; preds = %30
%38 = load i8, i8* %34
%39 = icmp eq i8 %38, 35
br i1 %39, label %52, label %40
40: ; preds = %37
%41 = load i32, i32* %3
%42 = add i32 %20, -1
%43 = add i32 %42, %41
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %31, i64 %44
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 92
br i1 %47, label %52, label %54
48: ; preds = %30, %27
%49 = phi i8* [ null, %27 ], [ %31, %30 ]
%50 = phi i32 [ %24, %27 ], [ %32, %30 ]
%51 = phi i32 [ 1, %27 ], [ 10, %30 ]
br label %57
52: ; preds = %40, %37
%53 = phi i32 [ %20, %37 ], [ %43, %40 ]
br label %17
54: ; preds = %40
%55 = call i32 @read_pseudo_def(%struct.pseudo** %0, i8* %31)
%56 = icmp eq i32 %55, 0
br i1 %56, label %62, label %57
57: ; preds = %54, %48
%58 = phi i32 [ %32, %54 ], [ %50, %48 ]
%59 = phi i8* [ %31, %54 ], [ %49, %48 ]
%60 = phi i32 [ %55, %54 ], [ %16, %48 ]
%61 = phi i32 [ 0, %54 ], [ %51, %48 ]
switch i32 %61, label %67 [
i32 0, label %13
i32 5, label %62
i32 10, label %62
]
62: ; preds = %54, %57, %57
%63 = phi i32 [ %60, %57 ], [ %60, %57 ], [ 0, %54 ]
%64 = phi i8* [ %59, %57 ], [ %59, %57 ], [ %31, %54 ]
%65 = call i32 @fclose(i32* %4)
%66 = call i32 @free(i8* %64)
br label %67
67: ; preds = %57, %62, %8
%68 = phi i32 [ 0, %8 ], [ %63, %62 ], [ 0, %57 ]
ret i32 %68
}