#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int,
                           char const *);
int fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int write_str_to_file_path(const char *str, const char *fpath) {
  FILE *stream;
  if ((stream = fopen(fpath, "w")) == NULL) {
    do {
      fprintf(stderr,
              ""
              "\x1b[33;1m"
              "[%s:%d]\x1b[0m "
              "Unable to write to %s"
              "\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/methusael13/weather-wiz/refs/heads/"
              "master/src/util.c",
              112, fpath);
    } while (0);
    return -1;
  }
  int res;
  res = fputs(str, stream);
  fclose(stream);
  return res;
}


x86 assembly (clang, -O0):
<write_str_to_file_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a4 <write_str_to_file_path+0x64>
jmp    1173 <write_str_to_file_path+0x33>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%r8
lea    0xe7b(%rip),%rsi
lea    0xe9e(%rip),%rdx
mov    $0x70,%ecx
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <write_str_to_file_path+0x83>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <fputs@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_str_to_file_path>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xeac(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     117d <write_str_to_file_path+0x3d>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    11a6 <write_str_to_file_path+0x66>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe75(%rip),%rsi
lea    0xe98(%rip),%rdx
mov    $0x70,%ecx
mov    %r15,%r8
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"\1B[33;1m[%s:%d]\1B[0m Unable to write to %s\0A\00"
@.str.2 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/methusael13/weather-wiz/refs/heads/master/src/util.c\00"
define i32 @write_str_to_file_path(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %17
11: ; preds = %2
br label %12
12: ; preds = %11
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %5
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.2, i64 0, i64 0), i32 112, i8* %14)
br label %16
16: ; preds = %12
store i32 -1, i32* %3
br label %24
17: ; preds = %2
%18 = load i8*, i8** %4
%19 = load i32*, i32** %6
%20 = call i32 @fputs(i8* %18, i32* %19)
store i32 %20, i32* %7
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %24
24: ; preds = %17, %16
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.1 = [42 x i8] c"\1B[33;1m[%s:%d]\1B[0m Unable to write to %s\0A\00"
@.str.2 = [143 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/methusael13/weather-wiz/refs/heads/master/src/util.c\00"
define i32 @write_str_to_file_path(i8* nocapture %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([143 x i8], [143 x i8]* @.str.2, i64 0, i64 0), i32 112, i8* %1)
br label %11
8: ; preds = %2
%9 = tail call i32 @fputs(i8* %0, i32* %3)
%10 = tail call i32 @fclose(i32* %3)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ -1, %5 ], [ %9, %8 ]
ret i32 %12
}