#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 */
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int strlen(char *);
void pidOpen(char *inmon, char *pidpath, char *stdwlan) {
  FILE *fpid;
  errno = 0;
  while ((fpid = fopen(pidpath, "r")) != NULL)
    pidpath[strlen(pidpath) - 1]++;
  inmon[strlen(inmon) - 1] = pidpath[strlen(pidpath) - 1];
  if ((fpid = fopen(pidpath, "w")) == NULL)
    fprintf(stderr,
            "Warning: Unable to write PID file \"%s\" (%s), this may cause "
            "problems running multiple instances of this program!\n\n",
            pidpath, strerror(errno));
  else {
    fprintf(fpid, "%s\n", stdwlan);
    fclose(fpid);
  }
}


x86 assembly (clang, -O0):
<pidOpen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e6d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11bb <pidOpen+0x6b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
add    $0x1,%dl
mov    %dl,(%rax,%rcx,1)
jmp    1172 <pidOpen+0x22>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x31(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x31(%rbp),%dl
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1262 <pidOpen+0x112>
mov    0x2dba(%rip),%rax
movslq (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2d9c(%rip),%rax
mov    (%rax),%rdi
call   1070 <strerror@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1281 <pidOpen+0x131>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pidOpen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    0x2e6d(%rip),%r13
movq   $0x0,0x0(%r13)
lea    0xe86(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11af <pidOpen+0x5f>
lea    0xe72(%rip),%r12
xchg   %ax,%ax
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
addb   $0x1,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    1190 <pidOpen+0x40>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
mov    -0x1(%rax,%rbx,1),%bpl
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
mov    %bpl,-0x1(%rax,%r15,1)
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     120e <pidOpen+0xbe>
mov    %rax,%r15
lea    0xe8c(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
mov    0x2dcb(%rip),%rax
movslq (%rax),%r14
mov    0x0(%r13),%rdi
call   1070 <strerror@plt>
lea    0xddc(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@errno = global i64 0
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [115 x i8] c"Warning: Unable to write PID file \22%s\22 (%s), this may cause problems running multiple instances of this program!\0A\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @pidOpen(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i64 0, i64* @errno
br label %8
8: ; preds = %12, %3
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %21
12: ; preds = %8
%13 = load i8*, i8** %5
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %13, i64 %17
%19 = load i8, i8* %18
%20 = add i8 %19, 1
store i8 %20, i8* %18
br label %8
21: ; preds = %8
%22 = load i8*, i8** %5
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %22, i64 %26
%28 = load i8, i8* %27
%29 = load i8*, i8** %4
%30 = load i8*, i8** %4
%31 = call i32 @strlen(i8* %30)
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %29, i64 %33
store i8 %28, i8* %34
%35 = load i8*, i8** %5
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %36, i32** %7
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %46
38: ; preds = %21
%39 = load i32, i32* @stderr
%40 = sext i32 %39 to i64
%41 = inttoptr i64 %40 to i32*
%42 = load i8*, i8** %5
%43 = load i64, i64* @errno
%44 = call i8* @strerror(i64 %43)
%45 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %41, i8* getelementptr inbounds ([115 x i8], [115 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %44)
br label %52
46: ; preds = %21
%47 = load i32*, i32** %7
%48 = load i8*, i8** %6
%49 = call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = load i32*, i32** %7
%51 = call i32 @fclose(i32* %50)
br label %52
52: ; preds = %46, %38
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@stderr = global i32 0
@.str.2 = [115 x i8] c"Warning: Unable to write PID file \22%s\22 (%s), this may cause problems running multiple instances of this program!\0A\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @pidOpen(i8* %0, i8* %1, i8* %2) {
store i64 0, i64* @errno
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %15, label %6
6: ; preds = %3, %6
%7 = tail call i32 @strlen(i8* %1)
%8 = add nsw i32 %7, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = add i8 %11, 1
store i8 %12, i8* %10
%13 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %6
15: ; preds = %6, %3
%16 = tail call i32 @strlen(i8* %1)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = tail call i32 @strlen(i8* %0)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 %20, i8* %24
%25 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %34
27: ; preds = %15
%28 = load i32, i32* @stderr
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i32*
%31 = load i64, i64* @errno
%32 = tail call i8* @strerror(i64 %31)
%33 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %30, i8* getelementptr inbounds ([115 x i8], [115 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %32)
br label %37
34: ; preds = %15
%35 = tail call i32 (i32*, i8*, i8*, ...) @fprintf(i32* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%36 = tail call i32 @fclose(i32* %25)
br label %37
37: ; preds = %34, %27
ret void
}