#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 atoi(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int get_pid(void) {
  int pid;
  FILE *PID = NULL;
  char line[256];
  PID = fopen("/var/run/netled.pid", "r");
  if (NULL == PID || feof(PID)) {
    return -1;
  }
  while (!feof(PID)) {
    fgets(line, 255, PID);
    pid = atoi(line);
    if (pid > 1) {
      fclose(PID);
      return pid;
    }
  }
  fclose(PID);
  return -1;
}


x86 assembly (clang, -O0):
<get_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movq   $0x0,-0x10(%rbp)
lea    0xe96(%rip),%rdi
lea    0xea3(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
je     1199 <get_pid+0x49>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     11a5 <get_pid+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    1220 <get_pid+0xd0>
jmp    11aa <get_pid+0x5a>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11c9 <get_pid+0x79>
jmp    1210 <get_pid+0xc0>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xff,%esi
call   1040 <fgets@plt>
lea    -0x110(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    120b <get_pid+0xbb>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1220 <get_pid+0xd0>
jmp    11aa <get_pid+0x5a>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_pid>:
push   %rbp
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe9e(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     11cb <get_pid+0x7b>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11cb <get_pid+0x7b>
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    11be <get_pid+0x6e>
mov    %r14,%rdi
mov    $0xff,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
mov    %r14,%rdi
call   1070 <atoi@plt>
cmp    $0x2,%eax
jl     1190 <get_pid+0x40>
mov    %eax,%ebp
jmp    11c3 <get_pid+0x73>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/var/run/netled.pid\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_pid() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [256 x i8]
store i32* null, i32** %3
%5 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp eq i32* null, %6
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = load i32*, i32** %3
%10 = call i64 @feof(i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8, %0
store i32 -1, i32* %1
br label %35
13: ; preds = %8
br label %14
14: ; preds = %31, %13
%15 = load i32*, i32** %3
%16 = call i64 @feof(i32* %15)
%17 = icmp ne i64 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %32
19: ; preds = %14
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%21 = load i32*, i32** %3
%22 = call i32 @fgets(i8* %20, i32 255, i32* %21)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %2
%25 = load i32, i32* %2
%26 = icmp sgt i32 %25, 1
br i1 %26, label %27, label %31
27: ; preds = %19
%28 = load i32*, i32** %3
%29 = call i32 @fclose(i32* %28)
%30 = load i32, i32* %2
store i32 %30, i32* %1
br label %35
31: ; preds = %19
br label %14
32: ; preds = %14
%33 = load i32*, i32** %3
%34 = call i32 @fclose(i32* %33)
store i32 -1, i32* %1
br label %35
35: ; preds = %32, %27, %12
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [20 x i8] c"/var/run/netled.pid\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @get_pid() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 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 %18, label %5
5: ; preds = %0
%6 = tail call i64 @feof(i32* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %5, %11
%9 = call i64 @feof(i32* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = call i32 @fgets(i8* %2, i32 255, i32* %3)
%13 = call i32 @atoi(i8* %2)
%14 = icmp sgt i32 %13, 1
br i1 %14, label %15, label %8
15: ; preds = %8, %11
%16 = phi i32 [ %13, %11 ], [ -1, %8 ]
%17 = call i32 @fclose(i32* %3)
br label %18
18: ; preds = %15, %0, %5
%19 = phi i32 [ -1, %5 ], [ -1, %0 ], [ %16, %15 ]
ret i32 %19
}