#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 *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int getpid();
int /*<<< orphan*/ gpm_report(int, char *, int, char *, ...);
int kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ unlink(char *);
void check_uniqueness(void) {
  FILE *fp = 0;
  int old_pid = -1;
  if ((fp = fopen("/var/run/"
                  "gpm.pid",
                  "r")) != NULL) {
    fscanf(fp, "%d", &old_pid);
    if (kill(old_pid, 0) == -1) {
      gpm_report(192,
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/ipwndev/DSLinux-Mirror/"
                 "refs/heads/master/lib/gpm/src/gpn.c",
                 3, "Removing stale pid file %s",
                 "/var/run/"
                 "gpm.pid");
      unlink("/var/run/"
             "gpm.pid");
    } else
      gpm_report(195,
                 "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                 "outputs/2022-01-22/02-19-57/repos/ipwndev/DSLinux-Mirror/"
                 "refs/heads/master/lib/gpm/src/gpn.c",
                 6, "gpm is already running as pid %d", old_pid);
  }
  if ((fp = fopen("/var/run/"
                  "gpm.pid",
                  "w")) != NULL) {
    fprintf(fp, "%d\n", getpid());
    fclose(fp);
  } else {
    gpm_report(202,
               "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
               "outputs/2022-01-22/02-19-57/repos/ipwndev/DSLinux-Mirror/refs/"
               "heads/master/lib/gpm/src/gpn.c",
               6, "Can you write to %s?",
               "/var/run/"
               "gpm.pid");
  }
}


x86 assembly (clang, -O0):
<check_uniqueness>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
lea    0xe62(%rip),%rdi
lea    0xe6c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     123e <check_uniqueness+0xbe>
mov    -0x8(%rbp),%rdi
lea    0xf1e(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <fscanf@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1080 <kill@plt>
cmp    $0xffffffff,%eax
jne    1216 <check_uniqueness+0x96>
mov    $0xc0,%edi
lea    0xe28(%rip),%rsi
mov    $0x3,%edx
lea    0xeb1(%rip),%rcx
lea    0xe02(%rip),%r8
mov    $0x0,%al
call   10a0 <gpm_report@plt>
lea    0xdf4(%rip),%rdi
call   1030 <unlink@plt>
jmp    1239 <check_uniqueness+0xb9>
mov    -0xc(%rbp),%r8d
mov    $0xc3,%edi
lea    0xded(%rip),%rsi
mov    $0x6,%edx
lea    0xe91(%rip),%rcx
mov    $0x0,%al
call   10a0 <gpm_report@plt>
jmp    123e <check_uniqueness+0xbe>
lea    0xdbb(%rip),%rdi
lea    0xe98(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     128e <check_uniqueness+0x10e>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
lea    0xe6b(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <fclose@plt>
jmp    12b4 <check_uniqueness+0x134>
mov    $0xca,%edi
lea    0xd79(%rip),%rsi
mov    $0x6,%edx
lea    0xe44(%rip),%rcx
lea    0xd53(%rip),%r8
mov    $0x0,%al
call   10a0 <gpm_report@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_uniqueness>:
push   %rbx
sub    $0x10,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xe6c(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1220 <check_uniqueness+0xa0>
lea    0xf35(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1080 <kill@plt>
cmp    $0xffffffff,%eax
je     11ef <check_uniqueness+0x6f>
mov    0xc(%rsp),%r8d
lea    0xe3e(%rip),%rsi
lea    0xee7(%rip),%rcx
mov    $0xc3,%edi
mov    $0x6,%edx
xor    %eax,%eax
call   10a0 <gpm_report@plt>
jmp    1220 <check_uniqueness+0xa0>
lea    0xe1d(%rip),%rsi
lea    0xeab(%rip),%rcx
lea    0xdfc(%rip),%rbx
mov    $0xc0,%edi
mov    $0x3,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   10a0 <gpm_report@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
lea    0xdd9(%rip),%rdi
lea    0xeb6(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     125d <check_uniqueness+0xdd>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    1283 <check_uniqueness+0x103>
lea    0xdaf(%rip),%rsi
lea    0xe7f(%rip),%rcx
lea    0xd8e(%rip),%r8
mov    $0xca,%edi
mov    $0x6,%edx
xor    %eax,%eax
call   10a0 <gpm_report@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"/var/run/gpm.pid\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ipwndev/DSLinux-Mirror/refs/heads/master/lib/gpm/src/gpn.c\00"
@.str.4 = [27 x i8] c"Removing stale pid file %s\00"
@.str.5 = [33 x i8] c"gpm is already running as pid %d\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [4 x i8] c"%d\0A\00"
@.str.8 = [21 x i8] c"Can you write to %s?\00"
define void @check_uniqueness() {
%1 = alloca i32*
%2 = alloca i32
store i32* null, i32** %1
store i32 -1, i32* %2
%3 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = icmp ne i32* %3, null
br i1 %4, label %5, label %18
5: ; preds = %0
%6 = load i32*, i32** %1
%7 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = call i32 @kill(i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = call i32 (i32, i8*, i32, i8*, ...) @gpm_report(i32 192, i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.3, i64 0, i64 0), i32 3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %17
14: ; preds = %5
%15 = load i32, i32* %2
%16 = call i32 (i32, i8*, i32, i8*, ...) @gpm_report(i32 195, i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.3, i64 0, i64 0), i32 6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %11
br label %18
18: ; preds = %17, %0
%19 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %19, i32** %1
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %18
%22 = load i32*, i32** %1
%23 = call i32 (...) @getpid()
%24 = call i32 @fprintf(i32* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %23)
%25 = load i32*, i32** %1
%26 = call i32 @fclose(i32* %25)
br label %29
27: ; preds = %18
%28 = call i32 (i32, i8*, i32, i8*, ...) @gpm_report(i32 202, i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.3, i64 0, i64 0), i32 6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %21
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"/var/run/gpm.pid\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [149 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/ipwndev/DSLinux-Mirror/refs/heads/master/lib/gpm/src/gpn.c\00"
@.str.4 = [27 x i8] c"Removing stale pid file %s\00"
@.str.5 = [33 x i8] c"gpm is already running as pid %d\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [4 x i8] c"%d\0A\00"
@.str.8 = [21 x i8] c"Can you write to %s?\00"
define void @check_uniqueness() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 -1, i32* %1
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %16, label %5
5: ; preds = %0
%6 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = load i32, i32* %1
%8 = call i32 @kill(i32 %7, i32 0)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = call i32 (i32, i8*, i32, i8*, ...) @gpm_report(i32 192, i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.3, i64 0, i64 0), i32 3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @unlink(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %16
13: ; preds = %5
%14 = load i32, i32* %1
%15 = call i32 (i32, i8*, i32, i8*, ...) @gpm_report(i32 195, i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.3, i64 0, i64 0), i32 6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %10, %13, %0
%17 = call i32* @fopen(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = call i32 (...) @getpid()
%21 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %20)
%22 = call i32 @fclose(i32* %17)
br label %25
23: ; preds = %16
%24 = call i32 (i32, i8*, i32, i8*, ...) @gpm_report(i32 202, i8* getelementptr inbounds ([149 x i8], [149 x i8]* @.str.3, i64 0, i64 0), i32 6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
ret void
}