#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*/ EX_OSERR;
int /*<<< orphan*/ ddb_list_scripts(char *);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char *);
scalar_t__ strchr(char *, char);
scalar_t__ strlen(char *);
scalar_t__ sysctlbyname(char *, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                        char *, scalar_t__);
int /*<<< orphan*/ usage();
void ddb_script(int argc, char *argv[]) {
  if (argc != 2)
    usage();
  argv++;
  argc--;
  if (strchr(argv[0], '=') != 0) {
    if (sysctlbyname("debug.ddb.scripting.script", NULL, NULL, argv[0],
                     strlen(argv[0]) + 1) < 0)
      err(EX_OSERR, "sysctl: %s", "debug.ddb.scripting.scripts");
  } else
    ddb_list_scripts(argv[0]);
}


x86 assembly (clang, -O0):
<ddb_script>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x4(%rbp)
je     1180 <ddb_script+0x20>
mov    $0x0,%al
call   1060 <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),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     1210 <ddb_script+0xb0>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,%r8
add    $0x1,%r8
lea    0xe27(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1080 <sysctlbyname@plt>
cmp    $0x0,%rax
jge    120b <ddb_script+0xab>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
lea    0xe20(%rip),%rdx
call   1050 <err@plt>
jmp    121c <ddb_script+0xbc>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <ddb_list_scripts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ddb_script>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
je     1170 <ddb_script+0x10>
xor    %eax,%eax
call   1060 <usage@plt>
mov    0x8(%rbx),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    0x8(%rbx),%rbx
test   %rax,%rax
je     11ad <ddb_script+0x4d>
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%r8
lea    0xe66(%rip),%rdi
xor    %esi,%esi
xor    %edx,%edx
mov    %rbx,%rcx
call   1080 <sysctlbyname@plt>
test   %rax,%rax
js     11b6 <ddb_script+0x56>
pop    %rbx
ret
mov    %rbx,%rdi
pop    %rbx
jmp    1070 <ddb_list_scripts@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
lea    0xe59(%rip),%rdx
pop    %rbx
jmp    1050 <err@plt>

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

LLVM IR (-O2):
@.str = [27 x i8] c"debug.ddb.scripting.script\00"
@EX_OSERR = global i32 0
@.str.1 = [11 x i8] c"sysctl: %s\00"
@.str.2 = [28 x i8] c"debug.ddb.scripting.scripts\00"
define void @ddb_script(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 @strchr(i8* %8, i8 signext 61)
%10 = icmp eq i64 %9, 0
%11 = load i8*, i8** %7
br i1 %10, label %20, label %12
12: ; preds = %6
%13 = tail call i64 @strlen(i8* dereferenceable(1) %11)
%14 = add nsw i64 %13, 1
%15 = tail call i64 @sysctlbyname(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32* null, i32* null, i8* %11, i64 %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i32, i32* @EX_OSERR
%19 = tail call i32 @err(i32 %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
br label %22
20: ; preds = %6
%21 = tail call i32 @ddb_list_scripts(i8* %11)
br label %22
22: ; preds = %12, %17, %20
ret void
}