#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 scalar_t__ uid_t;
struct stat {
  int /*<<< orphan*/ st_mode;
};
typedef scalar_t__ gid_t;

/* Variables and functions */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
scalar_t__ chown(char *, scalar_t__, scalar_t__);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ stat(char *, struct stat *);
scalar_t__ unlink(char *);
int /*<<< orphan*/ write_log(int, char *, char *, ...);
int dir_pid(uid_t uid, gid_t gid) {
  int need_mkdir;
  struct stat buf;
  need_mkdir = 0;
  if (!stat("/var/run/hwmultd", &buf)) {
    if (!S_ISDIR(buf.st_mode)) {
      need_mkdir = 1;
      if (unlink("/var/run/hwmultd")) {
        write_log(1,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/blueness/hwmultd/refs/"
                  "heads/master/src/pidfile.c",
                  "unlink non-directory at %s failed", "/var/run/hwmultd");
        return 0;
      } else
        write_log(3,
                  "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/blueness/hwmultd/refs/"
                  "heads/master/src/pidfile.c",
                  "unlinked non-directory at %s", "/var/run/hwmultd");
    } else
      write_log(3,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/blueness/hwmultd/refs/heads/"
                "master/src/pidfile.c",
                "pid file directory already exists: %s", "/var/run/hwmultd");
  } else
    need_mkdir = 1;
  if (need_mkdir) {
    if (mkdir("/var/run/hwmultd", 0755)) {
      write_log(1,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/blueness/hwmultd/refs/heads/"
                "master/src/pidfile.c",
                "make pid dir failed: %s", "/var/run/hwmultd");
      return 0;
    } else
      write_log(3,
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/blueness/hwmultd/refs/heads/"
                "master/src/pidfile.c",
                "made pid dir: %s", "/var/run/hwmultd");
  }
  if (chown("/var/run/hwmultd", uid, gid)) {
    write_log(1,
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/blueness/hwmultd/refs/heads/master/"
              "src/pidfile.c",
              "chown %d %d pid dir failed: %s", (int)uid, (int)gid,
              "/var/run/hwmultd");
    return 0;
  } else
    write_log(3,
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/blueness/hwmultd/refs/heads/master/"
              "src/pidfile.c",
              "chowed %d %d pid dir: %s", (int)uid, (int)gid,
              "/var/run/hwmultd");
  return 1;
}


x86 assembly (clang, -O0):
<dir_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe82(%rip),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0x0,%eax
jne    1237 <dir_pid+0xd7>
mov    -0x20(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1211 <dir_pid+0xb1>
movl   $0x1,-0x1c(%rbp)
lea    0xe51(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
je     11eb <dir_pid+0x8b>
mov    $0x1,%edi
lea    0xe47(%rip),%rsi
lea    0xecb(%rip),%rdx
lea    0xe28(%rip),%rcx
mov    $0x0,%al
call   1070 <write_log@plt>
movl   $0x0,-0x4(%rbp)
jmp    1343 <dir_pid+0x1e3>
mov    $0x3,%edi
lea    0xe1a(%rip),%rsi
lea    0xec0(%rip),%rdx
lea    0xdfb(%rip),%rcx
mov    $0x0,%al
call   1070 <write_log@plt>
jmp    1232 <dir_pid+0xd2>
mov    $0x3,%edi
lea    0xdf4(%rip),%rsi
lea    0xeb7(%rip),%rdx
lea    0xdd5(%rip),%rcx
mov    $0x0,%al
call   1070 <write_log@plt>
jmp    123e <dir_pid+0xde>
movl   $0x1,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     12b6 <dir_pid+0x156>
lea    0xdb1(%rip),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
je     1290 <dir_pid+0x130>
mov    $0x1,%edi
lea    0xda2(%rip),%rsi
lea    0xe8b(%rip),%rdx
lea    0xd83(%rip),%rcx
mov    $0x0,%al
call   1070 <write_log@plt>
movl   $0x0,-0x4(%rbp)
jmp    1343 <dir_pid+0x1e3>
mov    $0x3,%edi
lea    0xd75(%rip),%rsi
lea    0xe76(%rip),%rdx
lea    0xd56(%rip),%rcx
mov    $0x0,%al
call   1070 <write_log@plt>
jmp    12b6 <dir_pid+0x156>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd3b(%rip),%rdi
call   1080 <chown@plt>
cmp    $0x0,%rax
je     130e <dir_pid+0x1ae>
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %eax,%r8d
mov    $0x1,%edi
lea    0xd24(%rip),%rsi
lea    0xe36(%rip),%rdx
lea    0xd05(%rip),%r9
mov    $0x0,%al
call   1070 <write_log@plt>
movl   $0x0,-0x4(%rbp)
jmp    1343 <dir_pid+0x1e3>
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %eax,%r8d
mov    $0x3,%edi
lea    0xcea(%rip),%rsi
lea    0xe1b(%rip),%rdx
lea    0xccb(%rip),%r9
mov    $0x0,%al
call   1070 <write_log@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_pid>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe8c(%rip),%rdi
mov    %rsp,%rsi
call   1060 <stat@plt>
test   %eax,%eax
je     11be <dir_pid+0x5e>
lea    0xe79(%rip),%rdi
mov    $0x1ed,%esi
call   1040 <mkdir@plt>
test   %rax,%rax
je     11d7 <dir_pid+0x77>
lea    0xe74(%rip),%rsi
lea    0xf5d(%rip),%rdx
lea    0xe55(%rip),%rcx
xor    %ebp,%ebp
mov    $0x1,%edi
xor    %eax,%eax
call   1070 <write_log@plt>
jmp    125e <dir_pid+0xfe>
mov    (%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %eax,%eax
je     126b <dir_pid+0x10b>
lea    0xf06(%rip),%rdx
jmp    11de <dir_pid+0x7e>
lea    0xf3b(%rip),%rdx
lea    0xe2c(%rip),%rsi
lea    0xe14(%rip),%rbx
xor    %ebp,%ebp
mov    $0x3,%edi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <write_log@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1080 <chown@plt>
lea    0xdff(%rip),%rsi
test   %rax,%rax
je     1239 <dir_pid+0xd9>
lea    0xf0c(%rip),%rdx
lea    0xddb(%rip),%r9
mov    $0x1,%edi
mov    %r15d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1070 <write_log@plt>
jmp    125e <dir_pid+0xfe>
lea    0xf09(%rip),%rdx
lea    0xdb9(%rip),%r9
mov    $0x3,%edi
mov    %r15d,%ecx
mov    %r14d,%r8d
xor    %eax,%eax
call   1070 <write_log@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd8e(%rip),%rdi
call   1030 <unlink@plt>
lea    0xd93(%rip),%rsi
test   %rax,%rax
je     128f <dir_pid+0x12f>
lea    0xe12(%rip),%rdx
jmp    11a4 <dir_pid+0x44>
lea    0xe28(%rip),%rdx
lea    0xd63(%rip),%rcx
mov    $0x3,%edi
xor    %eax,%eax
call   1070 <write_log@plt>
jmp    1180 <dir_pid+0x20>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [17 x i8] c"/var/run/hwmultd\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/blueness/hwmultd/refs/heads/master/src/pidfile.c\00"
@.str.2 = [34 x i8] c"unlink non-directory at %s failed\00"
@.str.3 = [29 x i8] c"unlinked non-directory at %s\00"
@.str.4 = [38 x i8] c"pid file directory already exists: %s\00"
@.str.5 = [24 x i8] c"make pid dir failed: %s\00"
@.str.6 = [17 x i8] c"made pid dir: %s\00"
@.str.7 = [31 x i8] c"chown %d %d pid dir failed: %s\00"
@.str.8 = [25 x i8] c"chowed %d %d pid dir: %s\00"
define i32 @dir_pid(i64 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.stat
store i64 %0, i64* %4
store i64 %1, i64* %5
store i32 0, i32* %6
%8 = call i32 @stat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %struct.stat* %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %2
%11 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @S_ISDIR(i32 %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %10
store i32 1, i32* %6
%16 = call i64 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 (i32, i8*, i8*, ...) @write_log(i32 1, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %56
20: ; preds = %15
%21 = call i32 (i32, i8*, i8*, ...) @write_log(i32 3, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20
br label %25
23: ; preds = %10
%24 = call i32 (i32, i8*, i8*, ...) @write_log(i32 3, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %22
br label %27
26: ; preds = %2
store i32 1, i32* %6
br label %27
27: ; preds = %26, %25
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = call i64 @mkdir(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 493)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 (i32, i8*, i8*, ...) @write_log(i32 1, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %56
35: ; preds = %30
%36 = call i32 (i32, i8*, i8*, ...) @write_log(i32 3, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %37
37: ; preds = %35
br label %38
38: ; preds = %37, %27
%39 = load i64, i64* %4
%40 = load i64, i64* %5
%41 = call i64 @chown(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %39, i64 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = load i64, i64* %4
%45 = trunc i64 %44 to i32
%46 = load i64, i64* %5
%47 = trunc i64 %46 to i32
%48 = call i32 (i32, i8*, i8*, ...) @write_log(i32 1, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %45, i32 %47, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %56
49: ; preds = %38
%50 = load i64, i64* %4
%51 = trunc i64 %50 to i32
%52 = load i64, i64* %5
%53 = trunc i64 %52 to i32
%54 = call i32 (i32, i8*, i8*, ...) @write_log(i32 3, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %51, i32 %53, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %55
55: ; preds = %49
store i32 1, i32* %3
br label %56
56: ; preds = %55, %43, %33, %18
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [17 x i8] c"/var/run/hwmultd\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/blueness/hwmultd/refs/heads/master/src/pidfile.c\00"
@.str.2 = [34 x i8] c"unlink non-directory at %s failed\00"
@.str.3 = [29 x i8] c"unlinked non-directory at %s\00"
@.str.4 = [38 x i8] c"pid file directory already exists: %s\00"
@.str.5 = [24 x i8] c"make pid dir failed: %s\00"
@.str.6 = [17 x i8] c"made pid dir: %s\00"
@.str.7 = [31 x i8] c"chown %d %d pid dir failed: %s\00"
@.str.8 = [25 x i8] c"chowed %d %d pid dir: %s\00"
define i32 @dir_pid(i64 %0, i64 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = call i32 @stat(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), %struct.stat* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %2
%8 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @S_ISDIR(i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %24
12: ; preds = %7
%13 = tail call i64 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = tail call i32 (i32, i8*, i8*, ...) @write_log(i32 1, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %35
17: ; preds = %12
%18 = tail call i32 (i32, i8*, i8*, ...) @write_log(i32 3, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %2, %17
%20 = tail call i64 @mkdir(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 493)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 (i32, i8*, i8*, ...) @write_log(i32 1, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %35
24: ; preds = %19, %7
%25 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), %7 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), %19 ]
%26 = tail call i32 (i32, i8*, i8*, ...) @write_log(i32 3, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%27 = tail call i64 @chown(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i64 %0, i64 %1)
%28 = icmp eq i64 %27, 0
%29 = trunc i64 %0 to i32
%30 = trunc i64 %1 to i32
br i1 %28, label %33, label %31
31: ; preds = %24
%32 = tail call i32 (i32, i8*, i8*, ...) @write_log(i32 1, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0), i32 %29, i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %35
33: ; preds = %24
%34 = tail call i32 (i32, i8*, i8*, ...) @write_log(i32 3, i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i32 %29, i32 %30, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %31, %22, %15
%36 = phi i32 [ 0, %22 ], [ 0, %31 ], [ 1, %33 ], [ 0, %15 ]
ret i32 %36
}