#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 /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int const);
FILE *get_zone_file(const int zone) {
  char filename[80];
  FILE *rval;
  assert(zone >= 0 && zone < 180);
  sprintf(filename, "/home/phred/gaia2/%03d.cat", zone);
  rval = fopen(filename, "rb");
  if (!rval) {
    printf("Couldn't open '%s'\n", filename);
    perror("error");
    exit(-1);
  }
  return (rval);
}


x86 assembly (clang, -O0):
<get_zone_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x69(%rbp)
jl     1187 <get_zone_file+0x27>
cmpl   $0xb4,-0x4(%rbp)
setl   %al
mov    %al,-0x69(%rbp)
mov    -0x69(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x60(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe5e(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
jne    11ec <get_zone_file+0x8c>
lea    -0x60(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
lea    0xe55(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x68(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_zone_file>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    %edi,%ebx
xor    %edi,%edi
cmp    $0xb4,%ebx
setb   %dil
call   1040 <assert@plt>
lea    0xe7f(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1070 <sprintf@plt>
lea    0xe86(%rip),%rsi
mov    %r14,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11aa <get_zone_file+0x4a>
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6d(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
lea    0xe72(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"/home/phred/gaia2/%03d.cat\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"Couldn't open '%s'\0A\00"
@.str.3 = [6 x i8] c"error\00"
define i32* @get_zone_file(i32 %0) {
%2 = alloca i32
%3 = alloca [80 x i8]
%4 = alloca i32*
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = icmp sge i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 180
br label %10
10: ; preds = %7, %1
%11 = phi i1 [ false, %1 ], [ %9, %7 ]
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* %2
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %4
%19 = load i32*, i32** %4
%20 = icmp ne i32* %19, null
br i1 %20, label %26, label %21
21: ; preds = %10
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %10
%27 = load i32*, i32** %4
ret i32* %27
}

LLVM IR (-O2):
@.str = [27 x i8] c"/home/phred/gaia2/%03d.cat\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [20 x i8] c"Couldn't open '%s'\0A\00"
@.str.3 = [6 x i8] c"error\00"
define noalias i32* @get_zone_file(i32 %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = icmp ult i32 %0, 180
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %14
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%12 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %1
ret i32* %8
}