#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*/ bail(char *);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int getppid();
int /*<<< orphan*/ *popen(char *, char *);
int snprintf(char *, int, char *, int);
int getpppid() {
  char pscmd[128];
  if (snprintf(pscmd, 100, "/bin/ps -oppid= %d", getppid()) > 80) {
    bail("Failed to get PPPID.  This should never happen.");
  }
  char *line = 0;
  size_t linecap;
  FILE *f = popen(pscmd, "r");
  if (getline(&line, &linecap, f) < 0) {
    bail("Failed to get PPPID.  This should never happen.");
  }
  return atoi(line);
}


x86 assembly (clang, -O0):
<getpppid>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    -0x80(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    $0x0,%al
call   1080 <getppid@plt>
mov    -0xa0(%rbp),%rdi
mov    %eax,%ecx
mov    $0x64,%esi
lea    0xe6e(%rip),%rdx
call   1030 <snprintf@plt>
cmp    $0x50,%eax
jle    11ac <getpppid+0x4c>
lea    0xe6c(%rip),%rdi
call   1040 <bail@plt>
movq   $0x0,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1050 <popen@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rdx
lea    -0x88(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1070 <getline@plt>
cmp    $0x0,%rax
jge    11fe <getpppid+0x9e>
lea    0xe1a(%rip),%rdi
call   1040 <bail@plt>
mov    -0x88(%rbp),%rdi
call   1060 <atoi@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getpppid>:
sub    $0x98,%rsp
xor    %eax,%eax
call   1080 <getppid@plt>
lea    0xe8b(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x64,%esi
mov    %eax,%ecx
call   1030 <snprintf@plt>
cmp    $0x51,%eax
jl     1197 <getpppid+0x37>
lea    0xe81(%rip),%rdi
call   1040 <bail@plt>
movq   $0x0,(%rsp)
lea    0xe9d(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1050 <popen@plt>
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1070 <getline@plt>
test   %rax,%rax
jns    11d1 <getpppid+0x71>
lea    0xe47(%rip),%rdi
call   1040 <bail@plt>
mov    (%rsp),%rdi
call   1060 <atoi@plt>
add    $0x98,%rsp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/bin/ps -oppid= %d\00"
@.str.1 = [48 x i8] c"Failed to get PPPID. This should never happen.\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @getpppid() {
%1 = alloca [128 x i8]
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32*
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%6 = call i32 (...) @getppid()
%7 = call i32 @snprintf(i8* %5, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp sgt i32 %7, 80
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @bail(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %0
store i8* null, i8** %2
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%13 = call i32* @popen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %4
%14 = load i32*, i32** %4
%15 = call i64 @getline(i8** %2, i64* %3, i32* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @bail(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
%20 = load i8*, i8** %2
%21 = call i32 @atoi(i8* %20)
ret i32 %21
}

LLVM IR (-O2):
@.str = [19 x i8] c"/bin/ps -oppid= %d\00"
@.str.1 = [48 x i8] c"Failed to get PPPID. This should never happen.\00"
@.str.2 = [2 x i8] c"r\00"
define i32 @getpppid() {
%1 = alloca [128 x i8]
%2 = alloca i8*
%3 = alloca i64
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = tail call i32 (...) @getppid()
%6 = call i32 @snprintf(i8* %4, i32 100, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp sgt i32 %6, 80
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @bail(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%12 = bitcast i64* %3 to i8*
%13 = call i32* @popen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = call i64 @getline(i8** %2, i64* %3, i32* %13)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @bail(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = load i8*, i8** %2
%20 = call i32 @atoi(i8* %19)
ret i32 %20
}