#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 kmod_ctx {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ kmod_log_null(struct kmod_ctx *, char *, char *);
unsigned int strcspn(char *, char *);
char *underscores(struct kmod_ctx *ctx, char *s) {
  unsigned int i;
  if (!s)
    return NULL;
  for (i = 0; s[i]; i++) {
    switch (s[i]) {
    case '-':
      s[i] = '_';
      break;
    case ']':
      kmod_log_null(ctx, "Unmatched bracket in %s\n", s);
      break;
    case '[':
      i += strcspn(&s[i], "]");
      if (!s[i])
        kmod_log_null(ctx, "Unmatched bracket in %s\n", s);
      break;
    }
  }
  return s;
}


x86 assembly (clang, -O0):
<underscores>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1148 <underscores+0x28>
movq   $0x0,-0x8(%rbp)
jmp    1228 <underscores+0x108>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmpb   $0x0,(%rax,%rcx,1)
je     1220 <underscores+0x100>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
sub    $0x2d,%eax
je     119e <underscores+0x7e>
jmp    117c <underscores+0x5c>
mov    -0x20(%rbp),%eax
sub    $0x5b,%eax
je     11c7 <underscores+0xa7>
jmp    118d <underscores+0x6d>
mov    -0x20(%rbp),%eax
sub    $0x5d,%eax
je     11ae <underscores+0x8e>
jmp    120d <underscores+0xed>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x5f,(%rax,%rcx,1)
jmp    120d <underscores+0xed>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe43(%rip),%rsi
call   1030 <kmod_log_null@plt>
jmp    120d <underscores+0xed>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    %rax,%rdi
lea    0xe41(%rip),%rsi
call   1040 <strcspn@plt>
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmpb   $0x0,(%rax,%rcx,1)
jne    1208 <underscores+0xe8>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdfd(%rip),%rsi
call   1030 <kmod_log_null@plt>
jmp    120d <underscores+0xed>
jmp    1212 <underscores+0xf2>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114f <underscores+0x2f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<underscores>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
test   %rsi,%rsi
je     11c6 <underscores+0xa6>
mov    0x0(%r13),%al
test   %al,%al
je     11c6 <underscores+0xa6>
mov    %rdi,%r14
xor    %ebp,%ebp
lea    0xeb1(%rip),%r15
lea    0xec3(%rip),%r12
mov    %r13,%rdi
jmp    1181 <underscores+0x61>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <kmod_log_null@plt>
add    $0x1,%ebp
mov    %r13,%rdi
add    %rbp,%rdi
movzbl 0x0(%r13,%rbp,1),%eax
test   %al,%al
je     11c6 <underscores+0xa6>
movsbl %al,%eax
cmp    $0x5d,%eax
je     1160 <underscores+0x40>
cmp    $0x5b,%eax
je     11a0 <underscores+0x80>
cmp    $0x2d,%eax
jne    116e <underscores+0x4e>
movb   $0x5f,(%rdi)
jmp    116e <underscores+0x4e>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rsi
call   1040 <strcspn@plt>
mov    %eax,%ebx
add    %ebp,%ebx
cmpb   $0x0,0x0(%r13,%rbx,1)
jne    11c2 <underscores+0xa2>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1030 <kmod_log_null@plt>
mov    %ebx,%ebp
jmp    116e <underscores+0x4e>
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.kmod_ctx = type { i32 }
@.str = [25 x i8] c"Unmatched bracket in %s\0A\00"
@.str.1 = [2 x i8] c"]\00"
define i8* @underscores(%struct.kmod_ctx* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca %struct.kmod_ctx*
%5 = alloca i8*
%6 = alloca i32
store %struct.kmod_ctx* %0, %struct.kmod_ctx** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %2
store i8* null, i8** %3
br label %59
10: ; preds = %2
store i32 0, i32* %6
br label %11
11: ; preds = %54, %10
%12 = load i8*, i8** %5
%13 = load i32, i32* %6
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %57
18: ; preds = %11
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
switch i32 %24, label %53 [
i32 45, label %25
i32 93, label %30
i32 91, label %34
]
25: ; preds = %18
%26 = load i8*, i8** %5
%27 = load i32, i32* %6
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 95, i8* %29
br label %53
30: ; preds = %18
%31 = load %struct.kmod_ctx*, %struct.kmod_ctx** %4
%32 = load i8*, i8** %5
%33 = call i32 @kmod_log_null(%struct.kmod_ctx* %31, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %53
34: ; preds = %18
%35 = load i8*, i8** %5
%36 = load i32, i32* %6
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = call i32 @strcspn(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* %6
%41 = add i32 %40, %39
store i32 %41, i32* %6
%42 = load i8*, i8** %5
%43 = load i32, i32* %6
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = icmp ne i8 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %34
%49 = load %struct.kmod_ctx*, %struct.kmod_ctx** %4
%50 = load i8*, i8** %5
%51 = call i32 @kmod_log_null(%struct.kmod_ctx* %49, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %48, %34
br label %53
53: ; preds = %18, %52, %30, %25
br label %54
54: ; preds = %53
%55 = load i32, i32* %6
%56 = add i32 %55, 1
store i32 %56, i32* %6
br label %11
57: ; preds = %11
%58 = load i8*, i8** %5
store i8* %58, i8** %3
br label %59
59: ; preds = %57, %9
%60 = load i8*, i8** %3
ret i8* %60
}

LLVM IR (-O2):
%struct.kmod_ctx = type { i32 }
@.str = [25 x i8] c"Unmatched bracket in %s\0A\00"
@.str.1 = [2 x i8] c"]\00"
define i8* @underscores(%struct.kmod_ctx* %0, i8* %1) {
%3 = icmp eq i8* %1, null
br i1 %3, label %31, label %4
4: ; preds = %2
%5 = load i8, i8* %1
%6 = icmp eq i8 %5, 0
br i1 %6, label %31, label %7
7: ; preds = %4, %24
%8 = phi i8 [ %29, %24 ], [ %5, %4 ]
%9 = phi i8* [ %28, %24 ], [ %1, %4 ]
%10 = phi i32 [ %26, %24 ], [ 0, %4 ]
%11 = sext i8 %8 to i32
switch i32 %11, label %24 [
i32 45, label %12
i32 93, label %13
i32 91, label %15
]
12: ; preds = %7
store i8 95, i8* %9
br label %24
13: ; preds = %7
%14 = tail call i32 @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %24
15: ; preds = %7
%16 = tail call i32 @strcspn(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = add i32 %16, %10
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %1, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = tail call i32 @kmod_log_null(%struct.kmod_ctx* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %24
24: ; preds = %12, %13, %7, %22, %15
%25 = phi i32 [ %10, %7 ], [ %17, %15 ], [ %17, %22 ], [ %10, %13 ], [ %10, %12 ]
%26 = add i32 %25, 1
%27 = zext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %1, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 0
br i1 %30, label %31, label %7
31: ; preds = %24, %4, %2
ret i8* %1
}