#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 */
struct __sysctl_args {
  int *member_0;
  int member_1;
  char *member_2;
  int *member_3;
  char *member_4;
  int /*<<< orphan*/ newlen;
  int /*<<< orphan*/ *oldval;
  int /*<<< orphan*/ *newval;
  int /*<<< orphan*/ member_5;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int CTL_KERN;
int KERN_NODENAME;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int sysctl(struct __sysctl_args);
int main(int argc, char **argv) {
  int name[] = {CTL_KERN, KERN_NODENAME};
  int namelen = 2;
  char buffer[16];
  int len = sizeof(buffer);
  int error;
  struct __sysctl_args args = {
      name, namelen, buffer, &len, argv[1], 0,
  };
  if (argc == 1) {
    args.newval = NULL;
  } else if (argc == 2) {
    args.oldval = NULL;
    args.newlen = strlen(argv[1]);
  } else {
    fprintf(stderr, "%s: Specify 0 or 1 argument\n", argv[0]);
    exit(1);
  }
  error = sysctl(args);
  if (error) {
    fprintf(stderr, "%s: sysctl(): %s\n", argv[0], strerror(errno));
    exit(1);
  }
  if (argc == 1) {
    buffer[len + 1] = '\0';
    printf("%s\n", buffer);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x2,-0x1c(%rbp)
movl   $0x10,-0x34(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x78(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x70(%rbp)
lea    -0x34(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x58(%rbp)
movq   $0x0,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11fe <main+0x9e>
movq   $0x0,-0x48(%rbp)
jmp    1252 <main+0xf2>
cmpl   $0x2,-0x8(%rbp)
jne    1225 <main+0xc5>
movq   $0x0,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x58(%rbp)
jmp    124d <main+0xed>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1252 <main+0xf2>
mov    -0x40(%rbp),%rcx
mov    %rsp,%rax
mov    %rcx,0x40(%rax)
movups -0x80(%rbp),%xmm0
movups -0x70(%rbp),%xmm1
movups -0x60(%rbp),%xmm2
movups -0x50(%rbp),%xmm3
movups %xmm3,0x30(%rax)
movups %xmm2,0x20(%rax)
movups %xmm1,0x10(%rax)
movups %xmm0,(%rax)
call   1060 <sysctl@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     12e1 <main+0x181>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x88(%rbp)
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x8c(%rbp),%edi
mov    -0x88(%rbp),%rdx
mov    %rax,%rcx
lea    0xd4d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x1,-0x8(%rbp)
jne    1308 <main+0x1a8>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rsi
lea    0xd28(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0xb0,%rsp
mov    %rsi,%rbx
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x50(%rsp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x54(%rsp)
movl   $0x10,0x4c(%rsp)
lea    0x50(%rsp),%rax
mov    %rax,0x58(%rsp)
movl   $0x2,0x60(%rsp)
lea    0xa0(%rsp),%r14
mov    %r14,0x68(%rsp)
lea    0x4c(%rsp),%rax
mov    %rax,0x70(%rsp)
mov    0x8(%rsi),%rax
mov    %rax,0x78(%rsp)
movl   $0x0,0x80(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x88(%rsp)
movl   $0x0,0x98(%rsp)
cmp    $0x1,%edi
je     1247 <main+0xe7>
cmp    $0x2,%edi
jne    12e2 <main+0x182>
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %eax,0x80(%rsp)
mov    0x98(%rsp),%rax
mov    %rax,0x40(%rsp)
movups 0x58(%rsp),%xmm0
movups 0x68(%rsp),%xmm1
movups 0x78(%rsp),%xmm2
movups 0x88(%rsp),%xmm3
movups %xmm3,0x30(%rsp)
movups %xmm2,0x20(%rsp)
movups %xmm1,0x10(%rsp)
movups %xmm0,(%rsp)
call   1060 <sysctl@plt>
test   %eax,%eax
jne    12a8 <main+0x148>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x98(%rsp),%rax
mov    %rax,0x40(%rsp)
movups 0x58(%rsp),%xmm0
movups 0x68(%rsp),%xmm1
movups 0x78(%rsp),%xmm2
movups 0x88(%rsp),%xmm3
movups %xmm3,0x30(%rsp)
movups %xmm2,0x20(%rsp)
movups %xmm1,0x10(%rsp)
movups %xmm0,(%rsp)
call   1060 <sysctl@plt>
test   %eax,%eax
jne    12a8 <main+0x148>
movslq 0x4c(%rsp),%rax
movb   $0x0,0x1(%rax,%r14,1)
lea    0xd92(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xd54(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd0b(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.__sysctl_args = type { i32*, i32, i8*, i32*, i8*, i32, i32*, i32*, i32 }
@CTL_KERN = global i32 0
@KERN_NODENAME = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"%s: Specify 0 or 1 argument\0A\00"
@.str.1 = [18 x i8] c"%s: sysctl(): %s\0A\00"
@errno = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca [16 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.__sysctl_args
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%13 = load i32, i32* @CTL_KERN
store i32 %13, i32* %12
%14 = getelementptr inbounds i32, i32* %12, i64 1
%15 = load i32, i32* @KERN_NODENAME
store i32 %15, i32* %14
store i32 2, i32* %7
store i32 16, i32* %9
%16 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 0
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
store i32* %17, i32** %16
%18 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 1
%19 = load i32, i32* %7
store i32 %19, i32* %18
%20 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 2
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
store i8* %21, i8** %20
%22 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 3
store i32* %9, i32** %22
%23 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 4
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %23
%27 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 5
store i32 0, i32* %27
%28 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 6
store i32* null, i32** %28
%29 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 7
store i32* null, i32** %29
%30 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 8
store i32 0, i32* %30
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %35
33: ; preds = %2
%34 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 7
store i32* null, i32** %34
br label %53
35: ; preds = %2
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 2
br i1 %37, label %38, label %45
38: ; preds = %35
%39 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 6
store i32* null, i32** %39
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @strlen(i8* %42)
%44 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %11, i32 0, i32 5
store i32 %43, i32* %44
br label %52
45: ; preds = %35
%46 = load i32, i32* @stderr
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 0
%49 = load i8*, i8** %48
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %49)
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %38
br label %53
53: ; preds = %52, %33
%54 = call i32 @sysctl(%struct.__sysctl_args* byval(%struct.__sysctl_args) align 8 %11)
store i32 %54, i32* %10
%55 = load i32, i32* %10
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %66
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %61, i8* %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %53
%67 = load i32, i32* %4
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %76
69: ; preds = %66
%70 = load i32, i32* %9
%71 = add nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 %72
store i8 0, i8* %73
%74 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%75 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %69, %66
%77 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.__sysctl_args = type { i32*, i32, i8*, i32*, i8*, i32, i32*, i32*, i32 }
@CTL_KERN = global i32 0
@KERN_NODENAME = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"%s: Specify 0 or 1 argument\0A\00"
@.str.1 = [18 x i8] c"%s: sysctl(): %s\0A\00"
@errno = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca [16 x i8]
%5 = alloca i32
%6 = alloca %struct.__sysctl_args
%7 = bitcast [2 x i32]* %3 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%9 = load i32, i32* @CTL_KERN
store i32 %9, i32* %8
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%11 = load i32, i32* @KERN_NODENAME
store i32 %11, i32* %10
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%13 = bitcast i32* %5 to i8*
store i32 16, i32* %5
%14 = bitcast %struct.__sysctl_args* %6 to i8*
%15 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %6, i64 0, i32 0
store i32* %8, i32** %15
%16 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %6, i64 0, i32 1
store i32 2, i32* %16
%17 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %6, i64 0, i32 2
store i8* %12, i8** %17
%18 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %6, i64 0, i32 3
store i32* %5, i32** %18
%19 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %6, i64 0, i32 4
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %19
%22 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %6, i64 0, i32 5
store i32 0, i32* %22
%23 = getelementptr inbounds %struct.__sysctl_args, %struct.__sysctl_args* %6, i64 0, i32 6
%24 = bitcast i32** %23 to i8*
switch i32 %0, label %25 [
i32 1, label %30
i32 2, label %33
]
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %1
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %2
%31 = call i32 @sysctl(%struct.__sysctl_args* byval(%struct.__sysctl_args) align 8 %6)
%32 = icmp eq i32 %31, 0
br i1 %32, label %44, label %37
33: ; preds = %2
%34 = call i32 @strlen(i8* %21)
store i32 %34, i32* %22
%35 = call i32 @sysctl(%struct.__sysctl_args* byval(%struct.__sysctl_args) align 8 %6)
%36 = icmp eq i32 %35, 0
br i1 %36, label %50, label %37
37: ; preds = %33, %30
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %1
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %30
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %47
store i8 0, i8* %48
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %12)
br label %50
50: ; preds = %33, %44
%51 = call i32 @exit(i32 0)
unreachable
}