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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ zrpc_log(char *, char const *, int /*<<< orphan*/);
uint32_t zrpc_util_get_pid_output(const char *path) {
  FILE *fp;
  uint32_t pid;
  fp = fopen(path, "r");
  if (fp != NULL) {
    fscanf(fp, "%d\n", &pid);
    fclose(fp);
    return pid;
  }
  zrpc_log("Can't fopen pid lock file %s (%u), continuing", path, errno);
  return 0;
}


x86 assembly (clang, -O0):
<zrpc_util_get_pid_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1193 <zrpc_util_get_pid_output+0x53>
mov    -0x18(%rbp),%rdi
lea    0xe8c(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b3 <zrpc_util_get_pid_output+0x73>
mov    -0x10(%rbp),%rsi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
lea    0xe5f(%rip),%rdi
call   1030 <zrpc_log@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zrpc_util_get_pid_output>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xeb2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     117d <zrpc_util_get_pid_output+0x3d>
mov    %rax,%rbx
lea    0xea0(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x4(%rsp),%eax
jmp    1197 <zrpc_util_get_pid_output+0x57>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
lea    0xe79(%rip),%rdi
mov    %r14,%rsi
call   1030 <zrpc_log@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [46 x i8] c"Can't fopen pid lock file %s (%u), continuing\00"
@errno = global i32 0
define i32 @zrpc_util_get_pid_output(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %1
%11 = load i32*, i32** %4
%12 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %5)
%13 = load i32*, i32** %4
%14 = call i32 @fclose(i32* %13)
%15 = load i32, i32* %5
store i32 %15, i32* %2
br label %20
16: ; preds = %1
%17 = load i8*, i8** %3
%18 = load i32, i32* @errno
%19 = call i32 @zrpc_log(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32 %18)
store i32 0, i32* %2
br label %20
20: ; preds = %16, %10
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [46 x i8] c"Can't fopen pid lock file %s (%u), continuing\00"
@errno = global i32 0
define i32 @zrpc_util_get_pid_output(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%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 %10, label %6
6: ; preds = %1
%7 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = call i32 @fclose(i32* %4)
%9 = load i32, i32* %2
br label %13
10: ; preds = %1
%11 = load i32, i32* @errno
%12 = tail call i32 @zrpc_log(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %11)
br label %13
13: ; preds = %10, %6
%14 = phi i32 [ %9, %6 ], [ 0, %10 ]
ret i32 %14
}