#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 sysctlbyname(char *, char *, size_t *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/);
char *stringFromSysctlByName(char *name) {
  char *result = NULL;
  size_t length = 0;
  int complete = 0;
  int error = 0;
  while (!complete && !error) {
    assert(result == NULL);
    length = 0;
    error = sysctlbyname(name, NULL, &length, NULL, 0);
    if (!error) {
      result = malloc(length);
      if (result == NULL) {
        error = 1;
      }
    }
    if (!error) {
      error = sysctlbyname(name, 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):
<stringFromSysctlByName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x21(%rbp)
jne    1185 <stringFromSysctlByName+0x45>
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1195 <stringFromSysctlByName+0x55>
jmp    126d <stringFromSysctlByName+0x12d>
cmpq   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%rdx
xor    %r8d,%r8d
mov    %rcx,%rsi
call   1060 <sysctlbyname@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11f7 <stringFromSysctlByName+0xb7>
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f2 <stringFromSysctlByName+0xb2>
movl   $0x1,-0x20(%rbp)
jmp    11f7 <stringFromSysctlByName+0xb7>
cmpl   $0x0,-0x20(%rbp)
jne    1268 <stringFromSysctlByName+0x128>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
call   1060 <sysctlbyname@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1232 <stringFromSysctlByName+0xf2>
movl   $0x1,-0x1c(%rbp)
jmp    1263 <stringFromSysctlByName+0x123>
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,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
jmp    1268 <stringFromSysctlByName+0x128>
jmp    116a <stringFromSysctlByName+0x2a>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringFromSysctlByName>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
movq   $0x0,(%rsp)
mov    $0x1,%edi
call   1040 <assert@plt>
movq   $0x0,(%rsp)
xor    %r14d,%r14d
mov    %rsp,%rdx
mov    %r12,%rdi
xor    %esi,%esi
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <sysctlbyname@plt>
test   %eax,%eax
je     118d <stringFromSysctlByName+0x4d>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %r14d,%r14d
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     117e <stringFromSysctlByName+0x3e>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <sysctlbyname@plt>
test   %eax,%eax
je     1207 <stringFromSysctlByName+0xc7>
mov    $0x1,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1040 <assert@plt>
movq   $0x0,(%rsp)
mov    %r12,%rdi
xor    %esi,%esi
mov    %r15,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <sysctlbyname@plt>
test   %eax,%eax
je     11a0 <stringFromSysctlByName+0x60>
jmp    117e <stringFromSysctlByName+0x3e>
mov    %rbx,%r14
jmp    117e <stringFromSysctlByName+0x3e>

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

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