#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 */

/* Variables and functions */
int /*<<< orphan*/ getenv(char *);
int load_coef_AACGM(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
scalar_t__ strlen(char *);
int init_AACGM(int year) {
  char fname[256];
  char yrstr[32];
  if (year == 0)
    year = 1995;
  sprintf(yrstr, "%4.4d", year);
  strcpy(fname, getenv("AACGM_DAT_PREFIX"));
  if (strlen(fname) == 0)
    return -1;
  strcat(fname, yrstr);
  strcat(fname, ".asc");
  return load_coef_AACGM(fname);
}


x86 assembly (clang, -O0):
<init_AACGM>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    117f <init_AACGM+0x1f>
movl   $0x7cb,-0x8(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe70(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x138(%rbp)
lea    0xe5c(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x138(%rbp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    11df <init_AACGM+0x7f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <init_AACGM+0xb4>
lea    -0x110(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x110(%rbp),%rdi
lea    0xe17(%rip),%rsi
call   1070 <strcat@plt>
lea    -0x110(%rbp),%rdi
call   1060 <load_coef_AACGM@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_AACGM>:
push   %rbx
sub    $0x120,%rsp
test   %edi,%edi
mov    $0x7cb,%edx
cmovne %edi,%edx
lea    0xe97(%rip),%rsi
mov    %rsp,%rdi
call   1070 <sprintf@plt>
lea    0xe8e(%rip),%rdi
call   1030 <getenv@plt>
lea    0x20(%rsp),%rdi
mov    %eax,%esi
call   1040 <strcpy@plt>
cmpb   $0x0,0x20(%rsp)
je     11b9 <init_AACGM+0x69>
lea    0x20(%rsp),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
call   1050 <load_coef_AACGM@plt>
jmp    11be <init_AACGM+0x6e>
mov    $0xffffffff,%eax
add    $0x120,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%4.4d\00"
@.str.1 = [17 x i8] c"AACGM_DAT_PREFIX\00"
@.str.2 = [5 x i8] c".asc\00"
define i32 @init_AACGM(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca [32 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1995, i32* %3
br label %9
9: ; preds = %8, %1
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%11 = load i32, i32* %3
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%14 = call i32 @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @strcpy(i8* %13, i32 %14)
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%17 = call i64 @strlen(i8* %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %9
store i32 -1, i32* %2
br label %28
20: ; preds = %9
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%27 = call i32 @load_coef_AACGM(i8* %26)
store i32 %27, i32* %2
br label %28
28: ; preds = %20, %19
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@.str = [6 x i8] c"%4.4d\00"
@.str.1 = [17 x i8] c"AACGM_DAT_PREFIX\00"
@.str.2 = [5 x i8] c".asc\00"
define i32 @init_AACGM(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = icmp eq i32 %0, 0
%7 = select i1 %6, i32 1995, i32 %0
%8 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @getenv(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @strcpy(i8* %4, i32 %9)
%11 = load i8, i8* %4
%12 = icmp eq i8 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = call i32 @strcat(i8* %4, i8* %5)
%15 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 @load_coef_AACGM(i8* %4)
br label %17
17: ; preds = %1, %13
%18 = phi i32 [ %16, %13 ], [ -1, %1 ]
ret i32 %18
}