#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*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
FILE *get_gaia32_zone_file(const int zone_number, const char *path) {
  FILE *ifile;
  char filename[80];
  sprintf(filename,
          "%s"
          "/"
          "%03d.cat",
          path, zone_number);
  ifile = fopen(filename, "r");
  if (!ifile) {
    sprintf(filename, "%03d.cat", zone_number);
    ifile = fopen(filename, "r");
  }
  return (ifile);
}


x86 assembly (clang, -O0):
<get_gaia32_zone_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x4(%rbp),%ecx
lea    0xebf(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1190 <get_gaia32_zone_file+0x70>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe8e(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x70(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_gaia32_zone_file>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%rdx
mov    %edi,%ebp
lea    0xece(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%ecx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xec4(%rip),%rsi
mov    %rbx,%rdi
call   1030 <fopen@plt>
test   %rax,%rax
jne    117a <get_gaia32_zone_file+0x5a>
lea    0xea7(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
call   1030 <fopen@plt>
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s/%03d.cat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%03d.cat\00"
define i32* @get_gaia32_zone_file(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca [80 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%8 = load i8*, i8** %4
%9 = load i32, i32* %3
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %9)
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = icmp ne i32* %13, null
br i1 %14, label %21, label %15
15: ; preds = %2
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* %3
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %5
br label %21
21: ; preds = %15, %2
%22 = load i32*, i32** %5
ret i32* %22
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s/%03d.cat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%03d.cat\00"
define noalias i32* @get_gaia32_zone_file(i32 %0, i8* %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %0)
%6 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%10 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %8, %2
%12 = phi i32* [ %6, %2 ], [ %10, %8 ]
ret i32* %12
}