#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ getcwd(char *, int);
int main() {
  char sep = '/';
  char buf[1024];
  FILE *file;
  int i = 0;
  chdir("..");
  getcwd(buf, sizeof(buf));
  file = fopen("src/feline_home.asm", "w");
  if (file) {
    fprintf(file, "%%define FELINE_HOME \"%s\"\n", buf);
    fprintf(file, "%%define FELINE_SOURCE_DIR \"%s%csrc\"\n", buf, sep);
    fclose(file);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x2f,-0x5(%rbp)
movl   $0x0,-0x41c(%rbp)
lea    0xe89(%rip),%rdi
call   1040 <chdir@plt>
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
lea    0xe6f(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     11fd <main+0xad>
mov    -0x418(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xe4f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x418(%rbp),%rdi
lea    -0x410(%rbp),%rdx
movsbl -0x5(%rbp),%ecx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
lea    0xe9f(%rip),%rdi
call   1040 <chdir@plt>
mov    %rsp,%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
lea    0xe89(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c6 <main+0x76>
mov    %rax,%rbx
lea    0xe84(%rip),%rsi
mov    %rsp,%r14
mov    %rax,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe88(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x2f,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"..\00"
@.str.1 = [20 x i8] c"src/feline_home.asm\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [27 x i8] c"%%define FELINE_HOME \22%s\22\0A\00"
@.str.4 = [38 x i8] c"%%define FELINE_SOURCE_DIR \22%s%csrc\22\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [1024 x i8]
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
store i8 47, i8* %2
store i32 0, i32* %5
%6 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = call i32 @getcwd(i8* %7, i32 1024)
%9 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %23
12: ; preds = %0
%13 = load i32*, i32** %4
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %14)
%16 = load i32*, i32** %4
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %17, i32 %19)
%21 = load i32*, i32** %4
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %12, %0
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [3 x i8] c"..\00"
@.str.1 = [20 x i8] c"src/feline_home.asm\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [27 x i8] c"%%define FELINE_HOME \22%s\22\0A\00"
@.str.4 = [38 x i8] c"%%define FELINE_SOURCE_DIR \22%s%csrc\22\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @getcwd(i8* %2, i32 1024)
%5 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%9 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32 47)
%10 = call i32 @fclose(i32* %5)
br label %11
11: ; preds = %7, %0
ret i32 0
}