#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 ssize_t;
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ SIGKILL;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ abort();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, char const *, int /*<<< orphan*/ *);
scalar_t__ fork();
int /*<<< orphan*/ kill(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int read(int, char *, int);
long strtol(char *, int /*<<< orphan*/ *, int);
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
long exec_getconf(char const *var) {
  char buf[128];
  pid_t pid;
  int fd[2];
  int status;
  ssize_t l;
  if (pipe(fd) < 0 || (pid = fork()) < 0)
    abort();
  if (pid == 0) {
    close(fd[0]);
    if (fd[1] != 1) {
      dup2(fd[1], 1);
      close(fd[1]);
    }
    execlp("getconf", "getconf", var, NULL);
    _exit(1);
  }
  close(fd[1]);
  l = read(fd[0], buf, sizeof(buf) - 1);
  if (l < 0) {
    perror("read()");
    goto err;
  } else if (l == sizeof(buf) - 1)
    goto err;
  close(fd[0]);
  buf[l] = '\0';
  if (waitpid(pid, &status, 0) < 0)
    goto err;
  if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
    goto err;
  return strtol(buf, NULL, 10);
err:
  kill(pid, SIGKILL);
  abort();
}


x86 assembly (clang, -O0):
<exec_getconf>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0xa0(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0x0,%rax
jl     121d <exec_getconf+0x3d>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jge    1224 <exec_getconf+0x44>
mov    $0x0,%al
call   1030 <abort@plt>
cmpq   $0x0,-0x98(%rbp)
jne    1286 <exec_getconf+0xa6>
mov    -0xa0(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x1,-0x9c(%rbp)
je     1265 <exec_getconf+0x85>
mov    -0x9c(%rbp),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    -0x9c(%rbp),%edi
call   1060 <close@plt>
mov    -0x8(%rbp),%rdx
lea    0xd90(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
call   10f0 <execlp@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    -0x9c(%rbp),%edi
call   1060 <close@plt>
mov    -0xa0(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x7f,%edx
call   1080 <read@plt>
mov    %eax,-0xa8(%rbp)
cmpl   $0x0,-0xa8(%rbp)
jge    12cc <exec_getconf+0xec>
lea    0xd46(%rip),%rdi
call   10d0 <perror@plt>
jmp    1371 <exec_getconf+0x191>
movslq -0xa8(%rbp),%rax
cmp    $0x7f,%rax
jne    12e2 <exec_getconf+0x102>
jmp    1371 <exec_getconf+0x191>
jmp    12e7 <exec_getconf+0x107>
mov    -0xa0(%rbp),%edi
call   1060 <close@plt>
movslq -0xa8(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
mov    -0x98(%rbp),%rdi
lea    -0xa4(%rbp),%rsi
xor    %edx,%edx
call   10c0 <waitpid@plt>
cmp    $0x0,%rax
jge    1325 <exec_getconf+0x145>
jmp    1371 <exec_getconf+0x191>
mov    -0xa4(%rbp),%edi
call   10e0 <WIFEXITED@plt>
cmp    $0x0,%eax
je     134e <exec_getconf+0x16e>
mov    -0xa4(%rbp),%edi
call   10b0 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1353 <exec_getconf+0x173>
jmp    1371 <exec_getconf+0x191>
lea    -0x90(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1090 <strtol@plt>
add    $0xb0,%rsp
pop    %rbp
ret
mov    -0x98(%rbp),%rdi
mov    0x2c61(%rip),%rax
mov    (%rax),%esi
call   10a0 <kill@plt>
mov    $0x0,%al
call   1030 <abort@plt>

x86 assembly (clang, -O2):
<exec_getconf>:
push   %r15
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %rdi,%r14
lea    0x4(%rsp),%rdi
call   1070 <pipe@plt>
test   %rax,%rax
js     12ba <exec_getconf+0xda>
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
js     12ba <exec_getconf+0xda>
je     12c1 <exec_getconf+0xe1>
mov    %rax,%r15
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0x4(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x7f,%edx
call   1080 <read@plt>
test   %eax,%eax
js     129d <exec_getconf+0xbd>
cmp    $0x7f,%eax
je     12a9 <exec_getconf+0xc9>
mov    %eax,%ebx
mov    0x4(%rsp),%edi
call   1060 <close@plt>
movb   $0x0,0x10(%rsp,%rbx,1)
lea    0xc(%rsp),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   10c0 <waitpid@plt>
test   %rax,%rax
js     12a9 <exec_getconf+0xc9>
mov    0xc(%rsp),%edi
call   10e0 <WIFEXITED@plt>
test   %eax,%eax
je     12a9 <exec_getconf+0xc9>
mov    0xc(%rsp),%edi
call   10b0 <WEXITSTATUS@plt>
test   %rax,%rax
jne    12a9 <exec_getconf+0xc9>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1090 <strtol@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd64(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10a0 <kill@plt>
xor    %eax,%eax
call   1030 <abort@plt>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
cmp    $0x1,%edi
je     12e6 <exec_getconf+0x106>
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
lea    0xd13(%rip),%rdi
mov    %rdi,%rsi
mov    %r14,%rdx
xor    %ecx,%ecx
call   10f0 <execlp@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"getconf\00"
@.str.1 = [7 x i8] c"read()\00"
@SIGKILL = global i32 0
define i64 @exec_getconf(i8* %0) {
%2 = alloca i8*
%3 = alloca [128 x i8]
%4 = alloca i64
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%9 = call i64 @pipe(i32* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = call i64 (...) @fork()
store i64 %12, i64* %4
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11, %1
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %11
%17 = load i64, i64* %4
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %16
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%24 = load i32, i32* %23
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %33
26: ; preds = %19
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @dup2(i32 %28, i32 1)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @close(i32 %31)
br label %33
33: ; preds = %26, %19
%34 = load i8*, i8** %2
%35 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %34, i32* null)
%36 = call i32 @_exit(i32 1)
unreachable
37: ; preds = %16
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%42 = load i32, i32* %41
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%44 = call i32 @read(i32 %42, i8* %43, i32 127)
store i32 %44, i32* %7
%45 = load i32, i32* %7
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %37
%48 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %78
49: ; preds = %37
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = icmp eq i64 %51, 127
br i1 %52, label %53, label %54
53: ; preds = %49
br label %78
54: ; preds = %49
br label %55
55: ; preds = %54
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%57 = load i32, i32* %56
%58 = call i32 @close(i32 %57)
%59 = load i32, i32* %7
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %60
store i8 0, i8* %61
%62 = load i64, i64* %4
%63 = call i64 @waitpid(i64 %62, i32* %6, i32 0)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %55
br label %78
66: ; preds = %55
%67 = load i32, i32* %6
%68 = call i32 @WIFEXITED(i32 %67)
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %66
%71 = load i32, i32* %6
%72 = call i64 @WEXITSTATUS(i32 %71)
%73 = icmp ne i64 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %70, %66
br label %78
75: ; preds = %70
%76 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%77 = call i64 @strtol(i8* %76, i32* null, i32 10)
ret i64 %77
78: ; preds = %74, %65, %53, %47
%79 = load i64, i64* %4
%80 = load i32, i32* @SIGKILL
%81 = call i32 @kill(i64 %79, i32 %80)
%82 = call i32 (...) @abort()
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"getconf\00"
@.str.1 = [7 x i8] c"read()\00"
@SIGKILL = global i32 0
define i64 @exec_getconf(i8* %0) {
%2 = alloca [128 x i8]
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = bitcast [2 x i32]* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%9 = call i64 @pipe(i32* %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %1
%12 = call i64 (...) @fork()
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11, %1
%15 = call i32 (...) @abort()
unreachable
16: ; preds = %11
%17 = icmp eq i64 %12, 0
br i1 %17, label %18, label %31
18: ; preds = %16
%19 = load i32, i32* %8
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%22 = load i32, i32* %21
%23 = icmp eq i32 %22, 1
br i1 %23, label %28, label %24
24: ; preds = %18
%25 = call i32 @dup2(i32 %22, i32 1)
%26 = load i32, i32* %21
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %24, %18
%29 = call i32 @execlp(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0, i32* null)
%30 = call i32 @_exit(i32 1)
unreachable
31: ; preds = %16
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
%35 = load i32, i32* %8
%36 = call i32 @read(i32 %35, i8* %5, i32 127)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %59
40: ; preds = %31
%41 = icmp eq i32 %36, 127
br i1 %41, label %59, label %42
42: ; preds = %40
%43 = zext i32 %36 to i64
%44 = load i32, i32* %8
%45 = call i32 @close(i32 %44)
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %43
store i8 0, i8* %46
%47 = call i64 @waitpid(i64 %12, i32* %4, i32 0)
%48 = icmp slt i64 %47, 0
br i1 %48, label %59, label %49
49: ; preds = %42
%50 = load i32, i32* %4
%51 = call i32 @WIFEXITED(i32 %50)
%52 = icmp eq i32 %51, 0
br i1 %52, label %59, label %53
53: ; preds = %49
%54 = load i32, i32* %4
%55 = call i64 @WEXITSTATUS(i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i64 @strtol(i8* nocapture %5, i32* null, i32 10)
ret i64 %58
59: ; preds = %49, %53, %42, %40, %38
%60 = load i32, i32* @SIGKILL
%61 = call i32 @kill(i64 %12, i32 %60)
%62 = call i32 (...) @abort()
unreachable
}