#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*/ pid_t;
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
long strtol(char *, char **, int);
pid_t getMutex() {
  long int tpid = 0;
  char line[64];
  char *ptr = line;
  FILE *fin;
  fin = fopen("/tmp/.LazyLinux", "r");
  if (fin == NULL) {
    return 0;
  }
  memset(line, 0, sizeof(line));
  if (fread(line, 1, sizeof(line), fin) <= 0) {
    fclose(fin);
    return 0;
  }
  fclose(fin);
  tpid = strtol(line, &ptr, 10);
  if (tpid <= 0) {
    return 0;
  }
  if (ptr[0] != '\0') {
    return 0;
  }
  return (pid_t)tpid;
}


x86 assembly (clang, -O0):
<getMutex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movq   $0x0,-0x10(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    0xe91(%rip),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jne    1196 <getMutex+0x46>
movl   $0x0,-0x4(%rbp)
jmp    1235 <getMutex+0xe5>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
lea    -0x50(%rbp),%rdi
mov    -0x60(%rbp),%rcx
mov    $0x1,%esi
mov    $0x40,%edx
call   1030 <fread@plt>
cmp    $0x0,%rax
jg     11dc <getMutex+0x8c>
mov    -0x60(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1235 <getMutex+0xe5>
mov    -0x60(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x50(%rbp),%rdi
lea    -0x58(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jg     1212 <getMutex+0xc2>
movl   $0x0,-0x4(%rbp)
jmp    1235 <getMutex+0xe5>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     122e <getMutex+0xde>
movl   $0x0,-0x4(%rbp)
jmp    1235 <getMutex+0xe5>
mov    -0x10(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMutex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x58,%rsp
lea    0x10(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0xe95(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11e6 <getMutex+0x96>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x40,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rbp,%rbp
jle    11e9 <getMutex+0x99>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
test   %rax,%rax
jle    11e9 <getMutex+0x99>
mov    0x8(%rsp),%rcx
xor    %edx,%edx
cmpb   $0x0,(%rcx)
cmovne %edx,%eax
mov    %eax,%r15d
jmp    11e9 <getMutex+0x99>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/tmp/.LazyLinux\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @getMutex() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [64 x i8]
%4 = alloca i8*
%5 = alloca i32*
store i64 0, i64* %2
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
store i8* %6, i8** %4
%7 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %5
%8 = load i32*, i32** %5
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 0, i32* %1
br label %39
11: ; preds = %0
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 64)
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%15 = load i32*, i32** %5
%16 = call i64 @fread(i8* %14, i32 1, i32 64, i32* %15)
%17 = icmp sle i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32*, i32** %5
%20 = call i32 @fclose(i32* %19)
store i32 0, i32* %1
br label %39
21: ; preds = %11
%22 = load i32*, i32** %5
%23 = call i32 @fclose(i32* %22)
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%25 = call i64 @strtol(i8* %24, i8** %4, i32 10)
store i64 %25, i64* %2
%26 = load i64, i64* %2
%27 = icmp sle i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %21
store i32 0, i32* %1
br label %39
29: ; preds = %21
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
store i32 0, i32* %1
br label %39
36: ; preds = %29
%37 = load i64, i64* %2
%38 = trunc i64 %37 to i32
store i32 %38, i32* %1
br label %39
39: ; preds = %36, %35, %28, %18, %10
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [16 x i8] c"/tmp/.LazyLinux\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @getMutex() {
%1 = alloca [64 x i8]
%2 = alloca i8*
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = bitcast i8** %2 to i8*
store i8* %3, i8** %2
%5 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %21, label %7
7: ; preds = %0
%8 = call i32 @memset(i8* %3, i32 0, i32 64)
%9 = call i64 @fread(i8* %3, i32 1, i32 64, i32* %5)
%10 = icmp slt i64 %9, 1
%11 = call i32 @fclose(i32* %5)
br i1 %10, label %21, label %12
12: ; preds = %7
%13 = call i64 @strtol(i8* %3, i8** %2, i32 10)
%14 = icmp slt i64 %13, 1
br i1 %14, label %21, label %15
15: ; preds = %12
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
%19 = trunc i64 %13 to i32
%20 = select i1 %18, i32 %19, i32 0
br label %21
21: ; preds = %7, %15, %12, %0
%22 = phi i32 [ 0, %0 ], [ 0, %12 ], [ %20, %15 ], [ 0, %7 ]
ret i32 %22
}