#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 EOF;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ _debug(char *, int, int /*<<< orphan*/, char *, char const *,
                          int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getpid();
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *strrchr(char *, char);
void save_pid_file(const char *pf) {
  if (pf) {
    FILE *f = fopen(pf, "w");
    if (f) {
      fprintf(f, "%d\n", getpid());
      int ret = fclose(f);
      if (ret == EOF)
        _debug((strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                        "c-scraper/outputs/2022-01-22/02-19-57/repos/LeonKendy/"
                        "Wifi/refs/heads/master/src/util.c",
                        '/')
                    ? strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                              "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                              "LeonKendy/Wifi/refs/heads/master/src/util.c",
                              '/') +
                          1
                    : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/"
                      "heads/master/src/util.c"),
               186, LOG_ERR, "fclose() on file %s was failed (%s)", pf,
               strerror(errno));
    } else
      _debug((strrchr("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/"
                      "heads/master/src/util.c",
                      '/')
                  ? strrchr("/scratch/repos/new/home/jordi_armengol_estape/"
                            "c-scraper/outputs/2022-01-22/02-19-57/repos/"
                            "LeonKendy/Wifi/refs/heads/master/src/util.c",
                            '/') +
                        1
                  : "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/"
                    "heads/master/src/util.c"),
             188, LOG_ERR, "fopen() on flie %s was failed (%s)", pf,
             strerror(errno));
  }
  return;
}


x86 assembly (clang, -O0):
<save_pid_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1313 <save_pid_file+0x1a3>
mov    -0x8(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     127c <save_pid_file+0x10c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe40(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e0b(%rip),%rcx
cmp    (%rcx),%eax
jne    1277 <save_pid_file+0x107>
lea    0xe1a(%rip),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
cmp    $0x0,%rax
je     121e <save_pid_file+0xae>
lea    0xdff(%rip),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    122e <save_pid_file+0xbe>
lea    0xde1(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    122e <save_pid_file+0xbe>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%r8
mov    %eax,%r9d
mov    $0xba,%esi
lea    0xe1a(%rip),%rcx
call   1070 <_debug@plt>
jmp    130e <save_pid_file+0x19e>
lea    0xd83(%rip),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
cmp    $0x0,%rax
je     12b5 <save_pid_file+0x145>
lea    0xd68(%rip),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    12c5 <save_pid_file+0x155>
lea    0xd4a(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    12c5 <save_pid_file+0x155>
mov    -0x48(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x60(%rbp),%rdi
mov    -0x54(%rbp),%edx
mov    -0x50(%rbp),%r8
mov    %eax,%r9d
mov    $0xbc,%esi
lea    0xda7(%rip),%rcx
call   1070 <_debug@plt>
jmp    1313 <save_pid_file+0x1a3>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_pid_file>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11d7 <save_pid_file+0x77>
mov    %rdi,%r14
lea    0xe8d(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11df <save_pid_file+0x7f>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe74(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2e41(%rip),%rcx
cmp    (%rcx),%eax
jne    11d7 <save_pid_file+0x77>
mov    0x2e16(%rip),%rax
mov    (%rax),%ebx
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xebc(%rip),%rdi
lea    0xebc(%rip),%rcx
mov    $0xba,%esi
jmp    1209 <save_pid_file+0xa9>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2de2(%rip),%rax
mov    (%rax),%ebx
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe88(%rip),%rdi
lea    0xeac(%rip),%rcx
mov    $0xbc,%esi
mov    %ebx,%edx
mov    %r14,%r8
mov    %eax,%r9d
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <_debug@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@EOF = global i32 0
@.str.2 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/heads/master/src/util.c\00"
@LOG_ERR = global i32 0
@.str.3 = [36 x i8] c"fclose() on file %s was failed (%s)\00"
@errno = global i32 0
@.str.4 = [35 x i8] c"fopen() on flie %s was failed (%s)\00"
define void @save_pid_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %51
7: ; preds = %1
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %36
12: ; preds = %7
%13 = load i32*, i32** %3
%14 = call i32 (...) @getpid()
%15 = call i32 @fprintf(i32* %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32*, i32** %3
%17 = call i32 @fclose(i32* %16)
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %35
21: ; preds = %12
%22 = call i8* @strrchr(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.2, i64 0, i64 0), i8 signext 47)
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = call i8* @strrchr(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.2, i64 0, i64 0), i8 signext 47)
%26 = getelementptr inbounds i8, i8* %25, i64 1
br label %28
27: ; preds = %21
br label %28
28: ; preds = %27, %24
%29 = phi i8* [ %26, %24 ], [ getelementptr inbounds ([134 x i8], [134 x i8]* @.str.2, i64 0, i64 0), %27 ]
%30 = load i32, i32* @LOG_ERR
%31 = load i8*, i8** %2
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
%34 = call i32 @_debug(i8* %29, i32 186, i32 %30, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %31, i32 %33)
br label %35
35: ; preds = %28, %12
br label %50
36: ; preds = %7
%37 = call i8* @strrchr(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.2, i64 0, i64 0), i8 signext 47)
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = call i8* @strrchr(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.2, i64 0, i64 0), i8 signext 47)
%41 = getelementptr inbounds i8, i8* %40, i64 1
br label %43
42: ; preds = %36
br label %43
43: ; preds = %42, %39
%44 = phi i8* [ %41, %39 ], [ getelementptr inbounds ([134 x i8], [134 x i8]* @.str.2, i64 0, i64 0), %42 ]
%45 = load i32, i32* @LOG_ERR
%46 = load i8*, i8** %2
%47 = load i32, i32* @errno
%48 = call i32 @strerror(i32 %47)
%49 = call i32 @_debug(i8* %44, i32 188, i32 %45, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %46, i32 %48)
br label %50
50: ; preds = %43, %35
br label %51
51: ; preds = %50, %1
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@EOF = global i32 0
@.str.2 = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/LeonKendy/Wifi/refs/heads/master/src/util.c\00"
@LOG_ERR = global i32 0
@.str.3 = [36 x i8] c"fclose() on file %s was failed (%s)\00"
@errno = global i32 0
@.str.4 = [35 x i8] c"fopen() on flie %s was failed (%s)\00"
define void @save_pid_file(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %22, label %3
3: ; preds = %1
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %17, label %6
6: ; preds = %3
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @fprintf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 @fclose(i32* %4)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %22
12: ; preds = %6
%13 = load i32, i32* @LOG_ERR
%14 = load i32, i32* @errno
%15 = tail call i32 @strerror(i32 %14)
%16 = tail call i32 @_debug(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.2, i64 0, i64 127), i32 186, i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %15)
br label %22
17: ; preds = %3
%18 = load i32, i32* @LOG_ERR
%19 = load i32, i32* @errno
%20 = tail call i32 @strerror(i32 %19)
%21 = tail call i32 @_debug(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.2, i64 0, i64 127), i32 188, i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 %20)
br label %22
22: ; preds = %17, %12, %6, %1
ret void
}