#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int sysctl(int *, int, char *, size_t *, int /*<<< orphan*/ *,
           int /*<<< orphan*/);
char *stringFromSysctl(int mib0, int mib1) {
  char *result = NULL;
  int mib[2];
  mib[0] = mib0;
  mib[1] = mib1;
  size_t length = 0;
  int complete = 0;
  int error = 0;
  while (!complete && !error) {
    assert(result == NULL);
    length = 0;
    error = sysctl(mib, 2, NULL, &length, NULL, 0);
    if (!error) {
      result = malloc(length);
      if (result == NULL) {
        error = 1;
      }
    }
    if (!error) {
      error = sysctl(mib, 2, result, &length, NULL, 0);
      if (!error) {
        complete = 1;
      } else {
        assert(result != NULL);
        free(result);
        result = NULL;
        complete = 0;
        error = 0;
      }
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<stringFromSysctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x24(%rbp)
mov    %al,-0x29(%rbp)
jne    1193 <stringFromSysctl+0x53>
cmpl   $0x0,-0x28(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11a3 <stringFromSysctl+0x63>
jmp    1287 <stringFromSysctl+0x147>
cmpq   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movq   $0x0,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x2,%esi
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x20(%rbp),%rcx
xor    %r9d,%r9d
mov    %r8,%rdx
call   1060 <sysctl@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    120b <stringFromSysctl+0xcb>
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1206 <stringFromSysctl+0xc6>
movl   $0x1,-0x28(%rbp)
jmp    120b <stringFromSysctl+0xcb>
cmpl   $0x0,-0x28(%rbp)
jne    1282 <stringFromSysctl+0x142>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x2,%esi
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
xor    %r9d,%r9d
call   1060 <sysctl@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    124c <stringFromSysctl+0x10c>
movl   $0x1,-0x24(%rbp)
jmp    127d <stringFromSysctl+0x13d>
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
jmp    1282 <stringFromSysctl+0x142>
jmp    1178 <stringFromSysctl+0x38>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringFromSysctl>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,0x10(%rsp)
mov    %esi,0x14(%rsp)
movq   $0x0,0x8(%rsp)
mov    $0x1,%edi
call   1040 <assert@plt>
movq   $0x0,0x8(%rsp)
xor    %r14d,%r14d
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rcx
mov    $0x2,%esi
xor    %edx,%edx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <sysctl@plt>
test   %eax,%eax
je     11a1 <stringFromSysctl+0x61>
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %r14d,%r14d
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r12
xchg   %ax,%ax
mov    0x8(%rsp),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     1192 <stringFromSysctl+0x52>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x2,%esi
mov    %rax,%rdx
mov    %r12,%rcx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <sysctl@plt>
test   %eax,%eax
je     1225 <stringFromSysctl+0xe5>
mov    $0x1,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1040 <assert@plt>
movq   $0x0,0x8(%rsp)
mov    %r15,%rdi
mov    $0x2,%esi
xor    %edx,%edx
mov    %r12,%rcx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1060 <sysctl@plt>
test   %eax,%eax
je     11b0 <stringFromSysctl+0x70>
jmp    1192 <stringFromSysctl+0x52>
mov    %rbx,%r14
jmp    1192 <stringFromSysctl+0x52>

LLVM IR (-O0):
define i8* @stringFromSysctl(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [2 x i32]
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i8* null, i8** %5
%10 = load i32, i32* %3
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
store i32 %10, i32* %11
%12 = load i32, i32* %4
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
store i32 %12, i32* %13
store i64 0, i64* %7
store i32 0, i32* %8
store i32 0, i32* %9
br label %14
14: ; preds = %57, %2
%15 = load i32, i32* %8
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = load i32, i32* %9
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br label %21
21: ; preds = %17, %14
%22 = phi i1 [ false, %14 ], [ %20, %17 ]
br i1 %22, label %23, label %58
23: ; preds = %21
%24 = load i8*, i8** %5
%25 = icmp eq i8* %24, null
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
store i64 0, i64* %7
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%29 = call i32 @sysctl(i32* %28, i32 2, i8* null, i64* %7, i32* null, i32 0)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp ne i32 %30, 0
br i1 %31, label %39, label %32
32: ; preds = %23
%33 = load i64, i64* %7
%34 = call i8* @malloc(i64 %33)
store i8* %34, i8** %5
%35 = load i8*, i8** %5
%36 = icmp eq i8* %35, null
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 1, i32* %9
br label %38
38: ; preds = %37, %32
br label %39
39: ; preds = %38, %23
%40 = load i32, i32* %9
%41 = icmp ne i32 %40, 0
br i1 %41, label %57, label %42
42: ; preds = %39
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%44 = load i8*, i8** %5
%45 = call i32 @sysctl(i32* %43, i32 2, i8* %44, i64* %7, i32* null, i32 0)
store i32 %45, i32* %9
%46 = load i32, i32* %9
%47 = icmp ne i32 %46, 0
br i1 %47, label %49, label %48
48: ; preds = %42
store i32 1, i32* %8
br label %56
49: ; preds = %42
%50 = load i8*, i8** %5
%51 = icmp ne i8* %50, null
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = load i8*, i8** %5
%55 = call i32 @free(i8* %54)
store i8* null, i8** %5
store i32 0, i32* %8
store i32 0, i32* %9
br label %56
56: ; preds = %49, %48
br label %57
57: ; preds = %56, %39
br label %14
58: ; preds = %21
%59 = load i8*, i8** %5
ret i8* %59
}

LLVM IR (-O2):
define i8* @stringFromSysctl(i32 %0, i32 %1) {
%3 = alloca [2 x i32]
%4 = alloca i64
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
store i32 %0, i32* %6
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 %1, i32* %7
%8 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%9 = call i32 @assert(i32 1)
store i64 0, i64* %4
%10 = call i32 @sysctl(i32* %6, i32 2, i8* null, i64* %4, i32* null, i32 0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %25
12: ; preds = %2, %19
%13 = load i64, i64* %4
%14 = call i8* @malloc(i64 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %25, label %16
16: ; preds = %12
%17 = call i32 @sysctl(i32* %6, i32 2, i8* %14, i64* %4, i32* null, i32 0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = call i32 @assert(i32 1)
%21 = call i32 @free(i8* %14)
%22 = call i32 @assert(i32 1)
store i64 0, i64* %4
%23 = call i32 @sysctl(i32* %6, i32 2, i8* null, i64* %4, i32* null, i32 0)
%24 = icmp eq i32 %23, 0
br i1 %24, label %12, label %25
25: ; preds = %16, %19, %12, %2
%26 = phi i8* [ null, %2 ], [ %14, %16 ], [ null, %19 ], [ null, %12 ]
ret i8* %26
}