#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) {
    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    1256 <read_pseudo_file+0xf6>
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    1244 <read_pseudo_file+0xe4>
mov    -0x10(%rbp),%rdi
lea    -0x820(%rbp),%rsi
call   1060 <read_pseudo_def@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0x0,-0x824(%rbp)
jne    123f <read_pseudo_file+0xdf>
jmp    1244 <read_pseudo_file+0xe4>
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     11d6 <read_pseudo_file+0x76>
mov    %rax,%r15
lea    0xea2(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
test   %rax,%rax
jle    1205 <read_pseudo_file+0xa5>
mov    %rsp,%rbx
lea    0xe88(%rip),%r12
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <read_pseudo_def@plt>
test   %eax,%eax
je     120c <read_pseudo_file+0xac>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1040 <fscanf@plt>
test   %rax,%rax
jg     11b0 <read_pseudo_file+0x50>
jmp    120e <read_pseudo_file+0xae>
mov    0x2e03(%rip),%rax
mov    (%rax),%ebx
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe0e(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
xor    %ebp,%ebp
jmp    1216 <read_pseudo_file+0xb6>
mov    $0x1,%ebp
jmp    120e <read_pseudo_file+0xae>
xor    %ebp,%ebp
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %ebp,%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 %39
21: ; preds = %2
br label %22
22: ; preds = %34, %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 %35
27: ; preds = %22
%28 = load %struct.pseudo**, %struct.pseudo*** %4
%29 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%30 = call i32 @read_pseudo_def(%struct.pseudo** %28, i8* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
br label %35
34: ; preds = %27
br label %22
35: ; preds = %33, %22
%36 = load i32*, i32** %6
%37 = call i32 @fclose(i32* %36)
%38 = load i32, i32* %8
store i32 %38, i32* %3
br label %39
39: ; preds = %35, %20
%40 = load i32, i32* %3
ret i32 %40
}

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 %10, label %7
7: ; preds = %2
%8 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%9 = icmp sgt i64 %8, 0
br i1 %9, label %18, label %21
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %13)
br label %24
15: ; preds = %18
%16 = call i64 @fscanf(i32* %5, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %7, %15
%19 = call i32 @read_pseudo_def(%struct.pseudo** %0, i8* %4)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %15, %18, %7
%22 = phi i32 [ 1, %7 ], [ 0, %18 ], [ %19, %15 ]
%23 = call i32 @fclose(i32* %5)
br label %24
24: ; preds = %21, %10
%25 = phi i32 [ 0, %10 ], [ %22, %21 ]
ret i32 %25
}