#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*/ LOG_WARNING;
int /*<<< orphan*/ _log(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strcspn(char const *, char *);
const char *underscores2(const char *input, char *output, size_t outputlen) {
  size_t i;
  for (i = 0; input[i] != '\0' && i < outputlen - 1; i++) {
    switch (input[i]) {
    case '-':
      output[i] = '_';
      break;
    case ']':
      _log(LOG_WARNING, "Unmatched bracket in %s\n", input);
      return NULL;
    case '[': {
      size_t off = strcspn(input + i, "]");
      if (input[i + off] == '\0') {
        _log(LOG_WARNING, "Unmatched bracket in %s\n", input);
        return NULL;
      }
      memcpy(output + i, input + i, off + 1);
      i += off;
      break;
    }
    default:
      output[i] = input[i];
    }
  }
  output[i] = '\0';
  return output;
}


x86 assembly (clang, -O0):
<underscores2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     117b <underscores2+0x4b>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
setb   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    118b <underscores2+0x5b>
jmp    12b2 <underscores2+0x182>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x38(%rbp)
sub    $0x2d,%eax
je     11ca <underscores2+0x9a>
jmp    11a8 <underscores2+0x78>
mov    -0x38(%rbp),%eax
sub    $0x5b,%eax
je     1201 <underscores2+0xd1>
jmp    11b9 <underscores2+0x89>
mov    -0x38(%rbp),%eax
sub    $0x5d,%eax
je     11db <underscores2+0xab>
jmp    1286 <underscores2+0x156>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x5f,(%rax,%rcx,1)
jmp    129c <underscores2+0x16c>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe11(%rip),%rsi
call   1030 <_log@plt>
movq   $0x0,-0x8(%rbp)
jmp    12c6 <underscores2+0x196>
mov    -0x10(%rbp),%rdi
add    -0x28(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
add    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1258 <underscores2+0x128>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdba(%rip),%rsi
call   1030 <_log@plt>
movq   $0x0,-0x8(%rbp)
jmp    12c6 <underscores2+0x196>
mov    -0x18(%rbp),%rdi
add    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
add    $0x1,%rdx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rax
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    129c <underscores2+0x16c>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    12a1 <underscores2+0x171>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    114c <underscores2+0x1c>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<underscores2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    (%rdi),%al
xor    %r13d,%r13d
test   %al,%al
je     11ea <underscores2+0xba>
mov    %rdx,%r15
add    $0xffffffffffffffff,%r15
je     11ea <underscores2+0xba>
mov    %rdi,%r12
xor    %r13d,%r13d
mov    %rdi,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %al,%ecx
cmp    $0x2d,%ecx
je     1190 <underscores2+0x60>
cmp    $0x5b,%ecx
je     11a0 <underscores2+0x70>
cmp    $0x5d,%ecx
je     11f1 <underscores2+0xc1>
mov    %al,(%r14,%r13,1)
jmp    1195 <underscores2+0x65>
nopl   0x0(%rax,%rax,1)
movb   $0x5f,(%r14,%r13,1)
mov    %r13,%rbx
jmp    11cf <underscores2+0x9f>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
lea    0xe6f(%rip),%rsi
call   1040 <strcspn@plt>
lea    (%rax,%r13,1),%rbx
cmpb   $0x0,(%r12,%rbx,1)
je     11f1 <underscores2+0xc1>
add    %r14,%r13
add    $0x1,%rax
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1050 <memcpy@plt>
lea    0x1(%rbx),%r13
movzbl 0x1(%r12,%rbx,1),%eax
test   %al,%al
je     11ea <underscores2+0xba>
lea    (%r12,%rbx,1),%rbp
add    $0x1,%rbp
cmp    %r15,%r13
jb     1170 <underscores2+0x40>
movb   $0x0,(%r14,%r13,1)
jmp    120c <underscores2+0xdc>
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
lea    0xdff(%rip),%rsi
mov    %r12,%rdx
call   1030 <_log@plt>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@LOG_WARNING = global i32 0
@.str = [25 x i8] c"Unmatched bracket in %s\0A\00"
@.str.1 = [2 x i8] c"]\00"
define i8* @underscores2(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 0, i64* %8
br label %10
10: ; preds = %77, %3
%11 = load i8*, i8** %5
%12 = load i64, i64* %8
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %10
%18 = load i64, i64* %8
%19 = load i64, i64* %7
%20 = sub i64 %19, 1
%21 = icmp ult i64 %18, %20
br label %22
22: ; preds = %17, %10
%23 = phi i1 [ false, %10 ], [ %21, %17 ]
br i1 %23, label %24, label %80
24: ; preds = %22
%25 = load i8*, i8** %5
%26 = load i64, i64* %8
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
switch i32 %29, label %68 [
i32 45, label %30
i32 93, label %34
i32 91, label %38
]
30: ; preds = %24
%31 = load i8*, i8** %6
%32 = load i64, i64* %8
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8 95, i8* %33
br label %76
34: ; preds = %24
%35 = load i32, i32* @LOG_WARNING
%36 = load i8*, i8** %5
%37 = call i32 @_log(i32 %35, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %36)
store i8* null, i8** %4
br label %85
38: ; preds = %24
%39 = load i8*, i8** %5
%40 = load i64, i64* %8
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%42 = call i64 @strcspn(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i64 %42, i64* %9
%43 = load i8*, i8** %5
%44 = load i64, i64* %8
%45 = load i64, i64* %9
%46 = add i64 %44, %45
%47 = getelementptr inbounds i8, i8* %43, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %38
%52 = load i32, i32* @LOG_WARNING
%53 = load i8*, i8** %5
%54 = call i32 @_log(i32 %52, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %53)
store i8* null, i8** %4
br label %85
55: ; preds = %38
%56 = load i8*, i8** %6
%57 = load i64, i64* %8
%58 = getelementptr inbounds i8, i8* %56, i64 %57
%59 = load i8*, i8** %5
%60 = load i64, i64* %8
%61 = getelementptr inbounds i8, i8* %59, i64 %60
%62 = load i64, i64* %9
%63 = add i64 %62, 1
%64 = call i32 @memcpy(i8* %58, i8* %61, i64 %63)
%65 = load i64, i64* %9
%66 = load i64, i64* %8
%67 = add i64 %66, %65
store i64 %67, i64* %8
br label %76
68: ; preds = %24
%69 = load i8*, i8** %5
%70 = load i64, i64* %8
%71 = getelementptr inbounds i8, i8* %69, i64 %70
%72 = load i8, i8* %71
%73 = load i8*, i8** %6
%74 = load i64, i64* %8
%75 = getelementptr inbounds i8, i8* %73, i64 %74
store i8 %72, i8* %75
br label %76
76: ; preds = %68, %55, %30
br label %77
77: ; preds = %76
%78 = load i64, i64* %8
%79 = add i64 %78, 1
store i64 %79, i64* %8
br label %10
80: ; preds = %22
%81 = load i8*, i8** %6
%82 = load i64, i64* %8
%83 = getelementptr inbounds i8, i8* %81, i64 %82
store i8 0, i8* %83
%84 = load i8*, i8** %6
store i8* %84, i8** %4
br label %85
85: ; preds = %80, %51, %34
%86 = load i8*, i8** %4
ret i8* %86
}

LLVM IR (-O2):
@LOG_WARNING = global i32 0
@.str = [25 x i8] c"Unmatched bracket in %s\0A\00"
@.str.1 = [2 x i8] c"]\00"
define i8* @underscores2(i8* %0, i8* %1, i64 %2) {
%4 = add i64 %2, -1
%5 = load i8, i8* %0
%6 = icmp ne i8 %5, 0
%7 = icmp ne i64 %4, 0
%8 = and i1 %6, %7
br i1 %8, label %9, label %42
9: ; preds = %3, %34
%10 = phi i8 [ %38, %34 ], [ %5, %3 ]
%11 = phi i8* [ %37, %34 ], [ %0, %3 ]
%12 = phi i64 [ %36, %34 ], [ 0, %3 ]
%13 = sext i8 %10 to i32
switch i32 %13, label %32 [
i32 45, label %14
i32 93, label %16
i32 91, label %19
]
14: ; preds = %9
%15 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 95, i8* %15
br label %34
16: ; preds = %9
%17 = load i32, i32* @LOG_WARNING
%18 = tail call i32 @_log(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %45
19: ; preds = %9
%20 = tail call i64 @strcspn(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = add i64 %20, %12
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i32, i32* @LOG_WARNING
%27 = tail call i32 @_log(i32 %26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %45
28: ; preds = %19
%29 = getelementptr inbounds i8, i8* %1, i64 %12
%30 = add i64 %20, 1
%31 = tail call i32 @memcpy(i8* %29, i8* %11, i64 %30)
br label %34
32: ; preds = %9
%33 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 %10, i8* %33
br label %34
34: ; preds = %28, %14, %32
%35 = phi i64 [ %12, %32 ], [ %21, %28 ], [ %12, %14 ]
%36 = add i64 %35, 1
%37 = getelementptr inbounds i8, i8* %0, i64 %36
%38 = load i8, i8* %37
%39 = icmp ne i8 %38, 0
%40 = icmp ult i64 %36, %4
%41 = select i1 %39, i1 %40, i1 false
br i1 %41, label %9, label %42
42: ; preds = %34, %3
%43 = phi i64 [ 0, %3 ], [ %36, %34 ]
%44 = getelementptr inbounds i8, i8* %1, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %25, %42, %16
%46 = phi i8* [ null, %16 ], [ %1, %42 ], [ null, %25 ]
ret i8* %46
}