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

/* Variables and functions */
int charsetProcessorRead(struct stCharsetProcessor *, struct stCharset *,
                         struct stBitmap *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int pcxReaderRead(int /*<<< orphan*/ *, struct stBitmap *);
int /*<<< orphan*/ printf(char *, ...);
int readCharset(struct stCharsetProcessor *charsetProcessor,
                struct stCharset *charset, struct stBitmap *bitmap,
                char *pcxFilename, int verbose) {
  int i = 0;
  FILE *pcxFile = NULL;
  if (verbose)
    printf("Reading input file %s...\n", pcxFilename);
  if (!(pcxFile = fopen(pcxFilename, "rb"))) {
    printf("ERROR: Could not open %s.\n", pcxFilename);
    i = 21;
    goto out;
  }
  if ((i = pcxReaderRead(pcxFile, bitmap)))
    goto out;
  if (verbose)
    printf("Processing blocks...\n");
  if ((i = charsetProcessorRead(charsetProcessor, charset, bitmap)))
    goto out;
out:
  if (pcxFile)
    fclose(pcxFile);
  return i;
}


x86 assembly (clang, -O0):
<readCharset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1197 <readCharset+0x47>
mov    -0x20(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11d3 <readCharset+0x83>
mov    -0x20(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x15,-0x28(%rbp)
jmp    1230 <readCharset+0xe0>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <pcxReaderRead@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     11f1 <readCharset+0xa1>
jmp    1230 <readCharset+0xe0>
cmpl   $0x0,-0x24(%rbp)
je     1209 <readCharset+0xb9>
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <charsetProcessorRead@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     122b <readCharset+0xdb>
jmp    1230 <readCharset+0xe0>
jmp    1230 <readCharset+0xe0>
cmpq   $0x0,-0x30(%rbp)
je     1244 <readCharset+0xf4>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readCharset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r13d
mov    %rcx,%rbp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
test   %r8d,%r8d
je     1190 <readCharset+0x30>
lea    0xe7a(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe83(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11e3 <readCharset+0x83>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1060 <pcxReaderRead@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11d9 <readCharset+0x79>
test   %r13d,%r13d
je     11c9 <readCharset+0x69>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1070 <charsetProcessorRead@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11f9 <readCharset+0x99>
lea    0xe33(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x15,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stCharsetProcessor = type { i32 }
%struct.stCharset = type { i32 }
%struct.stBitmap = type { i32 }
@.str = [26 x i8] c"Reading input file %s...\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [27 x i8] c"ERROR: Could not open %s.\0A\00"
@.str.3 = [22 x i8] c"Processing blocks...\0A\00"
define i32 @readCharset(%struct.stCharsetProcessor* %0, %struct.stCharset* %1, %struct.stBitmap* %2, i8* %3, i32 %4) {
%6 = alloca %struct.stCharsetProcessor*
%7 = alloca %struct.stCharset*
%8 = alloca %struct.stBitmap*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32*
store %struct.stCharsetProcessor* %0, %struct.stCharsetProcessor** %6
store %struct.stCharset* %1, %struct.stCharset** %7
store %struct.stBitmap* %2, %struct.stBitmap** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
store i32 0, i32* %11
store i32* null, i32** %12
%13 = load i32, i32* %10
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = load i8*, i8** %9
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %15, %5
%19 = load i8*, i8** %9
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %12
%21 = icmp ne i32* %20, null
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i8*, i8** %9
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %23)
store i32 21, i32* %11
br label %44
25: ; preds = %18
%26 = load i32*, i32** %12
%27 = load %struct.stBitmap*, %struct.stBitmap** %8
%28 = call i32 @pcxReaderRead(i32* %26, %struct.stBitmap* %27)
store i32 %28, i32* %11
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %25
br label %44
31: ; preds = %25
%32 = load i32, i32* %10
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %31
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %31
%37 = load %struct.stCharsetProcessor*, %struct.stCharsetProcessor** %6
%38 = load %struct.stCharset*, %struct.stCharset** %7
%39 = load %struct.stBitmap*, %struct.stBitmap** %8
%40 = call i32 @charsetProcessorRead(%struct.stCharsetProcessor* %37, %struct.stCharset* %38, %struct.stBitmap* %39)
store i32 %40, i32* %11
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %43
42: ; preds = %36
br label %44
43: ; preds = %36
br label %44
44: ; preds = %43, %42, %30, %22
%45 = load i32*, i32** %12
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32*, i32** %12
%49 = call i32 @fclose(i32* %48)
br label %50
50: ; preds = %47, %44
%51 = load i32, i32* %11
ret i32 %51
}

LLVM IR (-O2):
%struct.stCharsetProcessor = type { i32 }
%struct.stCharset = type { i32 }
%struct.stBitmap = type { i32 }
@.str = [26 x i8] c"Reading input file %s...\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [27 x i8] c"ERROR: Could not open %s.\0A\00"
@str = [21 x i8] c"Processing blocks...\00"
define i32 @readCharset(%struct.stCharsetProcessor* %0, %struct.stCharset* %1, %struct.stBitmap* %2, i8* %3, i32 %4) {
%6 = icmp eq i32 %4, 0
br i1 %6, label %9, label %7
7: ; preds = %5
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %9
9: ; preds = %7, %5
%10 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %20, label %12
12: ; preds = %9
%13 = tail call i32 @pcxReaderRead(i32* %10, %struct.stBitmap* %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
br i1 %6, label %18, label %16
16: ; preds = %15
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %16, %15
%19 = tail call i32 @charsetProcessorRead(%struct.stCharsetProcessor* %0, %struct.stCharset* %1, %struct.stBitmap* %2)
br label %22
20: ; preds = %9
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %25
22: ; preds = %18, %12
%23 = phi i32 [ %19, %18 ], [ %13, %12 ]
%24 = tail call i32 @fclose(i32* %10)
br label %25
25: ; preds = %20, %22
%26 = phi i32 [ %23, %22 ], [ 21, %20 ]
ret i32 %26
}