#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 dag {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ dag_to_dax_footer(int /*<<< orphan*/ *);
int /*<<< orphan*/ dag_to_dax_header(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ dag_to_dax_nodes(struct dag const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ dag_to_dax_print_usage(char const *);
int /*<<< orphan*/ dag_to_dax_relationships(struct dag const *,
                                            int /*<<< orphan*/ *);
int /*<<< orphan*/ dag_to_dax_replica_catalog(struct dag const *,
                                              int /*<<< orphan*/ *);
int /*<<< orphan*/ dag_to_dax_transform_catalog(struct dag const *,
                                                int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int dag_to_dax(const struct dag *d, const char *name) {
  char dax_filename[PATH_MAX];
  sprintf(dax_filename, "%s.dax", name);
  FILE *dax = fopen(dax_filename, "w");
  dag_to_dax_header(name, dax);
  dag_to_dax_nodes(d, dax);
  dag_to_dax_relationships(d, dax);
  dag_to_dax_footer(dax);
  fclose(dax);
  sprintf(dax_filename, "%s.rc", name);
  dax = fopen(dax_filename, "w");
  dag_to_dax_replica_catalog(d, dax);
  fclose(dax);
  sprintf(dax_filename, "%s.tc", name);
  dax = fopen(dax_filename, "w");
  dag_to_dax_transform_catalog(d, dax);
  fclose(dax);
  dag_to_dax_print_usage(name);
  return 0;
}


x86 assembly (clang, -O0):
<dag_to_dax>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdx
lea    0xe19(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <dag_to_dax_header@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <dag_to_dax_nodes@plt>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <dag_to_dax_relationships@plt>
mov    -0x28(%rbp),%rdi
call   1070 <dag_to_dax_footer@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdc1(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10c0 <dag_to_dax_replica_catalog@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xd89(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <dag_to_dax_transform_catalog@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1080 <dag_to_dax_print_usage@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dag_to_dax>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xe2b(%rip),%rsi
mov    %r13,%rdi
mov    %r15,%rdx
call   10b0 <sprintf@plt>
lea    0xe20(%rip),%r12
mov    %r13,%rdi
mov    %r12,%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1030 <dag_to_dax_header@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <dag_to_dax_nodes@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <dag_to_dax_relationships@plt>
mov    %rbx,%rdi
call   1070 <dag_to_dax_footer@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xddc(%rip),%rsi
mov    %r13,%rdi
mov    %r15,%rdx
call   10b0 <sprintf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   10c0 <dag_to_dax_replica_catalog@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xdaf(%rip),%rsi
mov    %r13,%rdi
mov    %r15,%rdx
call   10b0 <sprintf@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <dag_to_dax_transform_catalog@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r15,%rdi
call   1080 <dag_to_dax_print_usage@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dag = type { i32 }
@PATH_MAX = global i32 0
@.str = [7 x i8] c"%s.dax\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"%s.rc\00"
@.str.3 = [6 x i8] c"%s.tc\00"
define i32 @dag_to_dax(%struct.dag* %0, i8* %1) {
%3 = alloca %struct.dag*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
store %struct.dag* %0, %struct.dag** %3
store i8* %1, i8** %4
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = load i8*, i8** %4
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i8*, i8** %4
%16 = load i32*, i32** %7
%17 = call i32 @dag_to_dax_header(i8* %15, i32* %16)
%18 = load %struct.dag*, %struct.dag** %3
%19 = load i32*, i32** %7
%20 = call i32 @dag_to_dax_nodes(%struct.dag* %18, i32* %19)
%21 = load %struct.dag*, %struct.dag** %3
%22 = load i32*, i32** %7
%23 = call i32 @dag_to_dax_relationships(%struct.dag* %21, i32* %22)
%24 = load i32*, i32** %7
%25 = call i32 @dag_to_dax_footer(i32* %24)
%26 = load i32*, i32** %7
%27 = call i32 @fclose(i32* %26)
%28 = load i8*, i8** %4
%29 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %7
%31 = load %struct.dag*, %struct.dag** %3
%32 = load i32*, i32** %7
%33 = call i32 @dag_to_dax_replica_catalog(%struct.dag* %31, i32* %32)
%34 = load i32*, i32** %7
%35 = call i32 @fclose(i32* %34)
%36 = load i8*, i8** %4
%37 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %7
%39 = load %struct.dag*, %struct.dag** %3
%40 = load i32*, i32** %7
%41 = call i32 @dag_to_dax_transform_catalog(%struct.dag* %39, i32* %40)
%42 = load i32*, i32** %7
%43 = call i32 @fclose(i32* %42)
%44 = load i8*, i8** %4
%45 = call i32 @dag_to_dax_print_usage(i8* %44)
%46 = load i8*, i8** %5
ret i32 0
}

LLVM IR (-O2):
%struct.dag = type { i32 }
@PATH_MAX = global i32 0
@.str = [7 x i8] c"%s.dax\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"%s.rc\00"
@.str.3 = [6 x i8] c"%s.tc\00"
define i32 @dag_to_dax(%struct.dag* %0, i8* %1) {
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @dag_to_dax_header(i8* %1, i32* %7)
%9 = tail call i32 @dag_to_dax_nodes(%struct.dag* %0, i32* %7)
%10 = tail call i32 @dag_to_dax_relationships(%struct.dag* %0, i32* %7)
%11 = tail call i32 @dag_to_dax_footer(i32* %7)
%12 = tail call i32 @fclose(i32* %7)
%13 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%14 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @dag_to_dax_replica_catalog(%struct.dag* %0, i32* %14)
%16 = tail call i32 @fclose(i32* %14)
%17 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%18 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @dag_to_dax_transform_catalog(%struct.dag* %0, i32* %18)
%20 = tail call i32 @fclose(i32* %18)
%21 = tail call i32 @dag_to_dax_print_usage(i8* %1)
ret i32 0
}