#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*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *strrchr(char *, char);
int sched_get_host_pid(const char *path) {
  static char *line = NULL;
  size_t size;
  int result = -1;
  FILE *sched_file = fopen(path, "r");
  if (sched_file != NULL) {
    if (getline(&line, &size, sched_file) != -1) {
      char *c = strrchr(line, '(');
      if (c != NULL) {
        result = atoi(c + 1);
      }
    }
    fclose(sched_file);
  }
  return result;
}


x86 assembly (clang, -O0):
<sched_get_host_pid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11dd <sched_get_host_pid+0x8d>
mov    -0x20(%rbp),%rdx
lea    0x2ec3(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     11d4 <sched_get_host_pid+0x84>
mov    0x2eaa(%rip),%rdi
mov    $0x28,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11cf <sched_get_host_pid+0x7f>
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    11d4 <sched_get_host_pid+0x84>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sched_get_host_pid>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b1 <sched_get_host_pid+0x61>
mov    %rax,%rbx
lea    0x2ee2(%rip),%rdi
mov    %rsp,%rsi
mov    %rax,%rdx
call   1070 <getline@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11a7 <sched_get_host_pid+0x57>
mov    0x2ec6(%rip),%rdi
mov    $0x28,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11a7 <sched_get_host_pid+0x57>
add    $0x1,%rax
mov    %rax,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11b6 <sched_get_host_pid+0x66>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@sched_get_host_pid.line = internal global i8* null
@.str = [2 x i8] c"r\00"
define i32 @sched_get_host_pid(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
store i8* %0, i8** %2
store i32 -1, i32* %4
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %5
%9 = load i32*, i32** %5
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %28
11: ; preds = %1
%12 = load i32*, i32** %5
%13 = call i32 @getline(i8** @sched_get_host_pid.line, i64* %3, i32* %12)
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i8*, i8** @sched_get_host_pid.line
%17 = call i8* @strrchr(i8* %16, i8 signext 40)
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %15
%21 = load i8*, i8** %6
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %4
br label %24
24: ; preds = %20, %15
br label %25
25: ; preds = %24, %11
%26 = load i32*, i32** %5
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %25, %1
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@sched_get_host_pid.line = internal global i8* null
@.str = [2 x i8] c"r\00"
define i32 @sched_get_host_pid(i8* nocapture %0) {
%2 = alloca i64
%3 = bitcast i64* %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 %19, label %6
6: ; preds = %1
%7 = call i32 @getline(i8** @sched_get_host_pid.line, i64* %2, i32* %4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = load i8*, i8** @sched_get_host_pid.line
%11 = call i8* @strrchr(i8* dereferenceable(1) %10, i8 signext 40)
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = call i32 @atoi(i8* %14)
br label %16
16: ; preds = %9, %13, %6
%17 = phi i32 [ -1, %6 ], [ %15, %13 ], [ -1, %9 ]
%18 = call i32 @fclose(i32* %4)
br label %19
19: ; preds = %16, %1
%20 = phi i32 [ %17, %16 ], [ -1, %1 ]
ret i32 %20
}