#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 S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ gethostname(char *, int);
int mkdir(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ umask(int);
FILE *open_debug_log(char *path, int rank, char *prefix) {
  char hostname[256];
  char nombre[2];
  int err = 0;
  sprintf(nombre, "%d", rank);
  gethostname(hostname, 256);
  umask(000);
  err = mkdir(path, S_IRWXU | S_IRWXG | S_IRWXO);
  strcat(path, "/");
  strcat(path, prefix);
  strcat(path, "_");
  strcat(path, hostname);
  strcat(path, "_");
  strcat(path, nombre);
  printf("PATH %s\n", path);
  return fopen(path, "w");
}


x86 assembly (clang, -O0):
<open_debug_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x128(%rbp)
lea    -0x122(%rbp),%rdi
mov    -0xc(%rbp),%edx
lea    0xe5f(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x120(%rbp),%rdi
mov    $0x100,%esi
call   1080 <gethostname@plt>
xor    %edi,%edi
call   1050 <umask@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
mov    0x2e06(%rip),%rax
or     (%rax),%esi
mov    0x2e15(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
mov    %eax,-0x128(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe10(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x122(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rsi
lea    0xdb7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xdb0(%rip),%rsi
call   1060 <fopen@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_debug_log>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdx,%r15
mov    %esi,%edx
mov    %rdi,%rbx
lea    0xe73(%rip),%rsi
lea    0xe(%rsp),%r14
mov    %r14,%rdi
call   1090 <sprintf@plt>
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0x100,%esi
call   1080 <gethostname@plt>
xor    %edi,%edi
call   1050 <umask@plt>
mov    0x2e26(%rip),%rax
mov    0x2e17(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e24(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1030 <mkdir@plt>
lea    0xe26(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
lea    0xe0e(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strcat@plt>
lea    0xddd(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
lea    0xdd7(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [2 x i8] c"_\00"
@.str.3 = [9 x i8] c"PATH %s\0A\00"
@.str.4 = [2 x i8] c"w\00"
define i32* @open_debug_log(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [256 x i8]
%8 = alloca [2 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %9
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%11 = load i32, i32* %5
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%14 = call i32 @gethostname(i8* %13, i32 256)
%15 = call i32 @umask(i32 0)
%16 = load i8*, i8** %4
%17 = load i32, i32* @S_IRWXU
%18 = load i32, i32* @S_IRWXG
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IRWXO
%21 = or i32 %19, %20
%22 = call i32 @mkdir(i8* %16, i32 %21)
store i32 %22, i32* %9
%23 = load i8*, i8** %4
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = load i8*, i8** %4
%26 = load i8*, i8** %6
%27 = call i32 @strcat(i8* %25, i8* %26)
%28 = load i8*, i8** %4
%29 = call i32 @strcat(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = load i8*, i8** %4
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%32 = call i32 @strcat(i8* %30, i8* %31)
%33 = load i8*, i8** %4
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = load i8*, i8** %4
%36 = getelementptr inbounds [2 x i8], [2 x i8]* %8, i64 0, i64 0
%37 = call i32 @strcat(i8* %35, i8* %36)
%38 = load i8*, i8** %4
%39 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %38)
%40 = load i8*, i8** %4
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32* %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [2 x i8] c"_\00"
@.str.3 = [9 x i8] c"PATH %s\0A\00"
@.str.4 = [2 x i8] c"w\00"
define noalias i32* @open_debug_log(i8* %0, i32 %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = alloca [2 x i8]
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%9 = call i32 @gethostname(i8* %6, i32 256)
%10 = call i32 @umask(i32 0)
%11 = load i32, i32* @S_IRWXU
%12 = load i32, i32* @S_IRWXG
%13 = or i32 %12, %11
%14 = load i32, i32* @S_IRWXO
%15 = or i32 %13, %14
%16 = call i32 @mkdir(i8* %0, i32 %15)
%17 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @strcat(i8* %0, i8* %2)
%19 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @strcat(i8* %0, i8* %6)
%21 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @strcat(i8* %0, i8* %7)
%23 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%24 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
ret i32* %24
}