#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 */
scalar_t__ EINVAL;
scalar_t__ ENOENT;
int /*<<< orphan*/ EX_DATAERR;
int /*<<< orphan*/ EX_OSERR;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char *);
scalar_t__ errno;
scalar_t__ strlen(char *);
int sysctlbyname(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *, char *,
                 scalar_t__);
int /*<<< orphan*/ usage();
void ddb_unscript(int argc, char *argv[]) {
  int ret;
  if (argc != 2)
    usage();
  argv++;
  argc--;
  ret = sysctlbyname("debug.ddb.scripting.unscript", NULL, NULL, argv[0],
                     strlen(argv[0]) + 1);
  if (ret < 0 && errno == EINVAL) {
    errno = ENOENT;
    err(EX_DATAERR, "sysctl: %s", argv[0]);
  } else if (ret < 0)
    err(EX_OSERR, "sysctl: %s", "debug.ddb.scripting.unscript");
}


x86 assembly (clang, -O0):
<ddb_unscript>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     1160 <ddb_unscript+0x20>
mov    $0x0,%al
call   1050 <usage@plt>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rcx
mov    %rax,%r8
add    $0x1,%r8
lea    0xe62(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1060 <sysctlbyname@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1206 <ddb_unscript+0xc6>
mov    0x2e1a(%rip),%rax
mov    (%rax),%rax
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%rax
jne    1206 <ddb_unscript+0xc6>
mov    0x2de0(%rip),%rax
mov    (%rax),%rcx
mov    0x2df6(%rip),%rax
mov    %rcx,(%rax)
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe21(%rip),%rsi
call   1040 <err@plt>
jmp    1231 <ddb_unscript+0xf1>
cmpl   $0x0,-0x14(%rbp)
jge    122c <ddb_unscript+0xec>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
lea    0xdd9(%rip),%rdx
call   1040 <err@plt>
jmp    1231 <ddb_unscript+0xf1>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ddb_unscript>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
je     1153 <ddb_unscript+0x13>
xor    %eax,%eax
call   1050 <usage@plt>
mov    0x8(%r14),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%r8
lea    0xe96(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %rbx,%rcx
call   1060 <sysctlbyname@plt>
test   %eax,%eax
js     1182 <ddb_unscript+0x42>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%rcx
mov    0x2e3d(%rip),%rdx
cmp    (%rdx),%rcx
jne    11bb <ddb_unscript+0x7b>
mov    0x2e19(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,(%rax)
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe64(%rip),%rsi
jmp    11d2 <ddb_unscript+0x92>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
lea    0xe2e(%rip),%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <err@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"debug.ddb.scripting.unscript\00"
@errno = global i64 0
@EINVAL = global i64 0
@ENOENT = global i64 0
@EX_DATAERR = global i32 0
@.str.1 = [11 x i8] c"sysctl: %s\00"
@EX_OSERR = global i32 0
define void @ddb_unscript(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 (...) @usage()
br label %10
10: ; preds = %8, %2
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i32 1
store i8** %12, i8*** %4
%13 = load i32, i32* %3
%14 = add nsw i32 %13, -1
store i32 %14, i32* %3
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i64 @strlen(i8* %20)
%22 = add nsw i64 %21, 1
%23 = call i32 @sysctlbyname(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32* null, i32* null, i8* %17, i64 %22)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %10
%27 = load i64, i64* @errno
%28 = load i64, i64* @EINVAL
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load i64, i64* @ENOENT
store i64 %31, i64* @errno
%32 = load i32, i32* @EX_DATAERR
%33 = load i8**, i8*** %4
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 @err(i32 %32, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %44
37: ; preds = %26, %10
%38 = load i32, i32* %5
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i32, i32* @EX_OSERR
%42 = call i32 @err(i32 %41, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %40, %37
br label %44
44: ; preds = %43, %30
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"debug.ddb.scripting.unscript\00"
@errno = global i64 0
@EINVAL = global i64 0
@ENOENT = global i64 0
@EX_DATAERR = global i32 0
@.str.1 = [11 x i8] c"sysctl: %s\00"
@EX_OSERR = global i32 0
define void @ddb_unscript(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strlen(i8* dereferenceable(1) %8)
%10 = add nsw i64 %9, 1
%11 = tail call i32 @sysctlbyname(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32* null, i32* null, i8* %8, i64 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %6
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINVAL
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i64, i64* @ENOENT
store i64 %18, i64* @errno
%19 = load i32, i32* @EX_DATAERR
%20 = load i8*, i8** %7
%21 = tail call i32 @err(i32 %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %25
22: ; preds = %13
%23 = load i32, i32* @EX_OSERR
%24 = tail call i32 @err(i32 %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %6, %22, %17
ret void
}