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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int currentRunlevel(void) {
  FILE *p;
  char response[50];
  p = popen("/sbin/runlevel", "r");
  if (!p)
    return -1;
  if (!fgets(response, sizeof(response), p)) {
    pclose(p);
    return -1;
  }
  pclose(p);
  if (response[1] != ' ' || !isdigit(response[2]) || response[3] != '\n')
    return -1;
  return response[2] - '0';
}


x86 assembly (clang, -O0):
<currentRunlevel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1176 <currentRunlevel+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <currentRunlevel+0xb1>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x32,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    11a6 <currentRunlevel+0x66>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <currentRunlevel+0xb1>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
movsbl -0x4f(%rbp),%eax
cmp    $0x20,%eax
jne    11db <currentRunlevel+0x9b>
movsbl -0x4e(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     11db <currentRunlevel+0x9b>
movsbl -0x4d(%rbp),%eax
cmp    $0xa,%eax
je     11e7 <currentRunlevel+0xa7>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f1 <currentRunlevel+0xb1>
movsbl -0x4e(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<currentRunlevel>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb9(%rip),%rsi
call   1060 <popen@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11ad <currentRunlevel+0x6d>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x32,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <pclose@plt>
test   %ebp,%ebp
je     11ad <currentRunlevel+0x6d>
cmpb   $0x20,0x1(%rsp)
jne    11ad <currentRunlevel+0x6d>
movsbl 0x2(%rsp),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11ad <currentRunlevel+0x6d>
cmpb   $0xa,0x3(%rsp)
jne    11ad <currentRunlevel+0x6d>
movsbl 0x2(%rsp),%r14d
add    $0xffffffd0,%r14d
mov    %r14d,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"/sbin/runlevel\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @currentRunlevel() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [50 x i8]
%4 = call i32* @popen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i32 -1, i32* %1
br label %39
8: ; preds = %0
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i32 @fgets(i8* %9, i32 50, i32* %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i32*, i32** %2
%15 = call i32 @pclose(i32* %14)
store i32 -1, i32* %1
br label %39
16: ; preds = %8
%17 = load i32*, i32** %2
%18 = call i32 @pclose(i32* %17)
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 1
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 32
br i1 %22, label %33, label %23
23: ; preds = %16
%24 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 2
%25 = load i8, i8* %24
%26 = call i32 @isdigit(i8 signext %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %23
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 3
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br i1 %32, label %33, label %34
33: ; preds = %28, %23, %16
store i32 -1, i32* %1
br label %39
34: ; preds = %28
%35 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 2
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = sub nsw i32 %37, 48
store i32 %38, i32* %1
br label %39
39: ; preds = %34, %33, %13, %7
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [15 x i8] c"/sbin/runlevel\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @currentRunlevel() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @popen(i8* getelementptr inbounds ([15 x i8], [15 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 %26, label %5
5: ; preds = %0
%6 = call i32 @fgets(i8* %2, i32 50, i32* %3)
%7 = icmp ne i32 %6, 0
%8 = call i32 @pclose(i32* %3)
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 32
%12 = select i1 %7, i1 %11, i1 false
br i1 %12, label %13, label %26
13: ; preds = %5
%14 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 2
%15 = load i8, i8* %14
%16 = call i32 @isdigit(i8 signext %15)
%17 = icmp eq i32 %16, 0
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 3
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 10
%21 = select i1 %17, i1 true, i1 %20
br i1 %21, label %26, label %22
22: ; preds = %13
%23 = load i8, i8* %14
%24 = sext i8 %23 to i32
%25 = add nsw i32 %24, -48
br label %26
26: ; preds = %5, %13, %0, %22
%27 = phi i32 [ %25, %22 ], [ -1, %0 ], [ -1, %13 ], [ -1, %5 ]
ret i32 %27
}