#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 */
unsigned int strcspn(char *, char *);
int /*<<< orphan*/ warn(char *, char *);
char *underscores(char *string) {
  unsigned int i;
  if (!string)
    return NULL;
  for (i = 0; string[i]; i++) {
    switch (string[i]) {
    case '-':
      string[i] = '_';
      break;
    case ']':
      warn("Unmatched bracket in %s\n", string);
      break;
    case '[':
      i += strcspn(&string[i], "]");
      if (!string[i])
        warn("Unmatched bracket in %s\n", string);
      break;
    }
  }
  return string;
}


x86 assembly (clang, -O0):
<underscores>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <underscores+0x24>
movq   $0x0,-0x8(%rbp)
jmp    121c <underscores+0xfc>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmpb   $0x0,(%rax,%rcx,1)
je     1214 <underscores+0xf4>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
sub    $0x2d,%eax
je     119a <underscores+0x7a>
jmp    1178 <underscores+0x58>
mov    -0x18(%rbp),%eax
sub    $0x5b,%eax
je     11bf <underscores+0x9f>
jmp    1189 <underscores+0x69>
mov    -0x18(%rbp),%eax
sub    $0x5d,%eax
je     11aa <underscores+0x8a>
jmp    1201 <underscores+0xe1>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x5f,(%rax,%rcx,1)
jmp    1201 <underscores+0xe1>
mov    -0x10(%rbp),%rsi
lea    0xe4b(%rip),%rdi
call   1030 <warn@plt>
jmp    1201 <underscores+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
lea    0xe49(%rip),%rsi
call   1040 <strcspn@plt>
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
cmpb   $0x0,(%rax,%rcx,1)
jne    11fc <underscores+0xdc>
mov    -0x10(%rbp),%rsi
lea    0xe09(%rip),%rdi
call   1030 <warn@plt>
jmp    1201 <underscores+0xe1>
jmp    1206 <underscores+0xe6>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <underscores+0x2b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<underscores>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r12
test   %rdi,%rdi
je     11c5 <underscores+0xa5>
mov    (%r12),%al
test   %al,%al
je     11c5 <underscores+0xa5>
xor    %ebx,%ebx
lea    0xeb6(%rip),%r14
lea    0xec8(%rip),%r15
mov    %r12,%rdi
jmp    117b <underscores+0x5b>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <warn@plt>
add    $0x1,%ebx
lea    (%r12,%rbx,1),%rdi
movzbl (%r12,%rbx,1),%eax
test   %al,%al
je     11c5 <underscores+0xa5>
movsbl %al,%eax
cmp    $0x5d,%eax
je     1160 <underscores+0x40>
cmp    $0x5b,%eax
je     11a0 <underscores+0x80>
cmp    $0x2d,%eax
jne    116b <underscores+0x4b>
movb   $0x5f,(%rdi)
jmp    116b <underscores+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rsi
call   1040 <strcspn@plt>
mov    %eax,%r13d
add    %ebx,%r13d
cmpb   $0x0,(%r12,%r13,1)
jne    11c0 <underscores+0xa0>
mov    %r14,%rdi
mov    %r12,%rsi
call   1030 <warn@plt>
mov    %r13d,%ebx
jmp    116b <underscores+0x4b>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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