#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*/ O_WRONLY;
int close(int);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int write(int, char const *, int);
int writeToFile(const char *dir, const char *file_name, const char *str) {
  char *path = malloc(sizeof(char) * (strlen(dir) + strlen(file_name) + 2));
  sprintf(path, "%s/%s", dir, file_name);
  int f = open(path, O_WRONLY);
  if (f == -1) {
    do {
      if (1) {
        fprintf(stderr, "%s: %d: ",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/CRUx-BPHC/crux-judge/refs/"
                "heads/development/src/resource_limits.c",
                103);
        fprintf(stderr, "open failed: errno: %d", errno);
        fprintf(stderr, "\n");
      }
    } while (0);
    free(path);
    return -1;
  }
  if (write(f, str, sizeof(char) * strlen(str)) == -1) {
    do {
      if (1) {
        fprintf(stderr, "%s: %d: ",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/CRUx-BPHC/crux-judge/refs/"
                "heads/development/src/resource_limits.c",
                108);
        fprintf(stderr, "write failed: errno: %d", errno);
        fprintf(stderr, "\n");
      }
    } while (0);
    free(path);
    return -1;
  }
  if (close(f) == -1) {
    do {
      if (1) {
        fprintf(stderr, "%s: %d: ",
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/CRUx-BPHC/crux-judge/refs/"
                "heads/development/src/resource_limits.c",
                113);
        fprintf(stderr, "close failed: errno: %d", errno);
        fprintf(stderr, "\n");
      }
    } while (0);
    free(path);
    return -1;
  }
  free(path);
  return 0;
}


x86 assembly (clang, -O0):
<writeToFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe29(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    126f <writeToFile+0xef>
jmp    1200 <writeToFile+0x80>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
lea    0xdf8(%rip),%rdx
mov    $0x67,%ecx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xe6f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <writeToFile+0x22c>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1317 <writeToFile+0x197>
jmp    12a8 <writeToFile+0x128>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
lea    0xd4e(%rip),%rsi
lea    0xd50(%rip),%rdx
mov    $0x6c,%ecx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
mov    0x2cfd(%rip),%rax
mov    (%rax),%edx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <writeToFile+0x22c>
mov    -0x2c(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    139c <writeToFile+0x21c>
jmp    132d <writeToFile+0x1ad>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
lea    0xcc9(%rip),%rsi
lea    0xccb(%rip),%rdx
mov    $0x71,%ecx
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
mov    0x2c78(%rip),%rax
mov    (%rax),%edx
lea    0xd73(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13ac <writeToFile+0x22c>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeToFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
lea    (%rax,%rbp,1),%edi
add    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
lea    0xe4b(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r12,%rcx
call   10a0 <sprintf@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1210 <writeToFile+0x90>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     121e <writeToFile+0x9e>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
jne    1272 <writeToFile+0xf2>
lea    0xed3(%rip),%r14
mov    $0x71,%ecx
jmp    122a <writeToFile+0xaa>
lea    0xe94(%rip),%r14
mov    $0x67,%ecx
jmp    122a <writeToFile+0xaa>
lea    0xe9f(%rip),%r14
mov    $0x6c,%ecx
mov    0x2daf(%rip),%rbx
mov    (%rbx),%edi
lea    0xdcc(%rip),%rsi
lea    0xdce(%rip),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
mov    0x2d87(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe5c(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [9 x i8] c"%s: %d: \00"
@.str.2 = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/CRUx-BPHC/crux-judge/refs/heads/development/src/resource_limits.c\00"
@.str.3 = [23 x i8] c"open failed: errno: %d\00"
@errno = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [24 x i8] c"write failed: errno: %d\00"
@.str.6 = [24 x i8] c"close failed: errno: %d\00"
define i32 @writeToFile(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = load i8*, i8** %6
%13 = call i32 @strlen(i8* %12)
%14 = add nsw i32 %11, %13
%15 = add nsw i32 %14, 2
%16 = sext i32 %15 to i64
%17 = mul i64 1, %16
%18 = trunc i64 %17 to i32
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = load i8*, i8** %5
%22 = load i8*, i8** %6
%23 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22)
%24 = load i8*, i8** %8
%25 = load i32, i32* @O_WRONLY
%26 = call i32 @open(i8* %24, i32 %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %41
29: ; preds = %3
br label %30
30: ; preds = %29
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.2, i64 0, i64 0), i32 103)
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %34)
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %38
38: ; preds = %30
%39 = load i8*, i8** %8
%40 = call i32 @free(i8* %39)
store i32 -1, i32* %4
br label %82
41: ; preds = %3
%42 = load i32, i32* %9
%43 = load i8*, i8** %7
%44 = load i8*, i8** %7
%45 = call i32 @strlen(i8* %44)
%46 = sext i32 %45 to i64
%47 = mul i64 1, %46
%48 = trunc i64 %47 to i32
%49 = call i32 @write(i32 %42, i8* %43, i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %63
51: ; preds = %41
br label %52
52: ; preds = %51
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.2, i64 0, i64 0), i32 108)
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %56)
%58 = load i32, i32* @stderr
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %60
60: ; preds = %52
%61 = load i8*, i8** %8
%62 = call i32 @free(i8* %61)
store i32 -1, i32* %4
br label %82
63: ; preds = %41
%64 = load i32, i32* %9
%65 = call i32 @close(i32 %64)
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %79
67: ; preds = %63
br label %68
68: ; preds = %67
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.2, i64 0, i64 0), i32 113)
%71 = load i32, i32* @stderr
%72 = load i32, i32* @errno
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %72)
%74 = load i32, i32* @stderr
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %76
76: ; preds = %68
%77 = load i8*, i8** %8
%78 = call i32 @free(i8* %77)
store i32 -1, i32* %4
br label %82
79: ; preds = %63
%80 = load i8*, i8** %8
%81 = call i32 @free(i8* %80)
store i32 0, i32* %4
br label %82
82: ; preds = %79, %76, %60, %38
%83 = load i32, i32* %4
ret i32 %83
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.1 = [9 x i8] c"%s: %d: \00"
@.str.2 = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/CRUx-BPHC/crux-judge/refs/heads/development/src/resource_limits.c\00"
@.str.3 = [23 x i8] c"open failed: errno: %d\00"
@errno = global i32 0
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [24 x i8] c"write failed: errno: %d\00"
@.str.6 = [24 x i8] c"close failed: errno: %d\00"
define i32 @writeToFile(i8* %0, i8* %1, i8* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = tail call i32 @strlen(i8* %1)
%6 = add i32 %4, 2
%7 = add i32 %6, %5
%8 = tail call i8* @malloc(i32 %7)
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %8, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%10 = load i32, i32* @O_WRONLY
%11 = tail call i32 @open(i8* %8, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %20, label %13
13: ; preds = %3
%14 = tail call i32 @strlen(i8* %2)
%15 = tail call i32 @write(i32 %11, i8* %2, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = tail call i32 @close(i32 %11)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %30
20: ; preds = %17, %13, %3
%21 = phi i32 [ 103, %3 ], [ 108, %13 ], [ 113, %17 ]
%22 = phi i8* [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %3 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), %13 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), %17 ]
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* %22, i32 %26)
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %20, %17
%31 = phi i32 [ 0, %17 ], [ -1, %20 ]
%32 = tail call i32 @free(i8* %8)
ret i32 %31
}