#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 *, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int read_pseudo_def(struct pseudo **, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int read_pseudo_file(struct pseudo **pseudo, char *filename) {
  FILE *fd;
  char line[2048];
  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 (fscanf(fd, "%2047[^\n]\n", line) > 0) {
    if (line[0] == '#')
      continue;
    res = read_pseudo_def(pseudo, line);
    if (res == 0)
      break;
  };
  fclose(fd);
  return res;
}


x86 assembly (clang, -O0):
<read_pseudo_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x824(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f1 <read_pseudo_file+0x91>
jmp    11a1 <read_pseudo_file+0x41>
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x834(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x830(%rbp)
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x834(%rbp),%edi
mov    -0x830(%rbp),%rdx
mov    %rax,%rcx
lea    0xe22(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    126b <read_pseudo_file+0x10b>
jmp    11f6 <read_pseudo_file+0x96>
mov    -0x20(%rbp),%rdi
lea    -0x820(%rbp),%rdx
lea    0xe2d(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x0,%rax
jle    1259 <read_pseudo_file+0xf9>
movsbl -0x820(%rbp),%eax
cmp    $0x23,%eax
jne    122c <read_pseudo_file+0xcc>
jmp    11f6 <read_pseudo_file+0x96>
mov    -0x10(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1060 <read_pseudo_def@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0x0,-0x824(%rbp)
jne    1254 <read_pseudo_file+0xf4>
jmp    1259 <read_pseudo_file+0xf9>
jmp    11f6 <read_pseudo_file+0x96>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x824(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_pseudo_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
lea    0xe84(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d8 <read_pseudo_file+0x78>
mov    %rax,%rbx
mov    $0x1,%r15d
lea    0xe9c(%rip),%r12
mov    %rsp,%rbp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
test   %rax,%rax
jle    11ce <read_pseudo_file+0x6e>
cmpb   $0x23,(%rsp)
je     11a0 <read_pseudo_file+0x40>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <read_pseudo_def@plt>
mov    %eax,%r15d
test   %eax,%eax
jne    11a0 <read_pseudo_file+0x40>
xor    %r15d,%r15d
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1206 <read_pseudo_file+0xa6>
mov    0x2e01(%rip),%rax
mov    (%rax),%ebx
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe0c(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
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 = [11 x i8] c"%2047[^\0A]\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 [2048 x i8]
%8 = alloca i32
store %struct.pseudo** %0, %struct.pseudo*** %4
store i8* %1, i8** %5
store i32 1, i32* %8
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %21
13: ; preds = %2
br label %14
14: ; preds = %13
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %5
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %18)
br label %20
20: ; preds = %14
store i32 0, i32* %3
br label %45
21: ; preds = %2
br label %22
22: ; preds = %40, %32, %21
%23 = load i32*, i32** %6
%24 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%25 = call i64 @fscanf(i32* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = icmp sgt i64 %25, 0
br i1 %26, label %27, label %41
27: ; preds = %22
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 35
br i1 %31, label %32, label %33
32: ; preds = %27
br label %22
33: ; preds = %27
%34 = load %struct.pseudo**, %struct.pseudo*** %4
%35 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%36 = call i32 @read_pseudo_def(%struct.pseudo** %34, i8* %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
br label %41
40: ; preds = %33
br label %22
41: ; preds = %39, %22
%42 = load i32*, i32** %6
%43 = call i32 @fclose(i32* %42)
%44 = load i32, i32* %8
store i32 %44, i32* %3
br label %45
45: ; preds = %41, %20
%46 = load i32, i32* %3
ret i32 %46
}

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 = [11 x i8] c"%2047[^\0A]\0A\00"
define i32 @read_pseudo_file(%struct.pseudo** %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %21
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %10)
br label %26
12: ; preds = %21, %15
%13 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i8, i8* %4
%17 = icmp eq i8 %16, 35
br i1 %17, label %12, label %18
18: ; preds = %15
%19 = call i32 @read_pseudo_def(%struct.pseudo** %0, i8* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %2, %18
%22 = phi i32 [ %19, %18 ], [ 1, %2 ]
br label %12
23: ; preds = %18, %12
%24 = phi i32 [ %22, %12 ], [ 0, %18 ]
%25 = call i32 @fclose(i32* %5)
br label %26
26: ; preds = %23, %7
%27 = phi i32 [ 0, %7 ], [ %24, %23 ]
ret i32 %27
}