unsigned int ip_scanbracket(s, ip)
char *s;
struct ip_address *ip;
{
  unsigned int len;
  if (*s != '[')
    return 0;
  len = ip_scan(s + 1, ip);
  if (!len)
    return 0;
  if (s[len + 1] != ']')
    return 0;
  return len + 2;
}


x86 assembly (clang, -O0):
<ip_scanbracket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5b,%eax
je     113c <ip_scanbracket+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    1196 <ip_scanbracket+0x86>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    $0x0,%al
call   1030 <ip_scan@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1168 <ip_scanbracket+0x58>
movl   $0x0,-0x4(%rbp)
jmp    1196 <ip_scanbracket+0x86>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5d,%eax
je     118d <ip_scanbracket+0x7d>
movl   $0x0,-0x4(%rbp)
jmp    1196 <ip_scanbracket+0x86>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_scanbracket>:
push   %rbp
push   %rbx
push   %rax
xor    %ebp,%ebp
cmpb   $0x5b,(%rdi)
jne    113d <ip_scanbracket+0x2d>
mov    %rdi,%rbx
add    $0x1,%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <ip_scan@plt>
test   %eax,%eax
je     113d <ip_scanbracket+0x2d>
lea    0x1(%rax),%ecx
add    $0x2,%eax
xor    %ebp,%ebp
cmpb   $0x5d,(%rbx,%rcx,1)
cmove  %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.ip_address = type opaque
define i32 @ip_scanbracket(i8* %0, %struct.ip_address* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.ip_address*
%6 = alloca i32
store i8* %0, i8** %4
store %struct.ip_address* %1, %struct.ip_address** %5
%7 = load i8*, i8** %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 91
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %33
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load %struct.ip_address*, %struct.ip_address** %5
%16 = call i32 (i8*, %struct.ip_address*, ...) bitcast (i32 (...)* @ip_scan to i32 (i8*, %struct.ip_address*, ...)*)(i8* %14, %struct.ip_address* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %12
store i32 0, i32* %3
br label %33
20: ; preds = %12
%21 = load i8*, i8** %4
%22 = load i32, i32* %6
%23 = add i32 %22, 1
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 93
br i1 %28, label %29, label %30
29: ; preds = %20
store i32 0, i32* %3
br label %33
30: ; preds = %20
%31 = load i32, i32* %6
%32 = add i32 %31, 2
store i32 %32, i32* %3
br label %33
33: ; preds = %30, %29, %19, %11
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
%struct.ip_address = type opaque
define i32 @ip_scanbracket(i8* %0, %struct.ip_address* %1) {
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 91
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %0, i64 1
%7 = tail call i32 (i8*, %struct.ip_address*, ...) bitcast (i32 (...)* @ip_scan to i32 (i8*, %struct.ip_address*, ...)*)(i8* %6, %struct.ip_address* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = add i32 %7, 1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 93
%15 = add i32 %7, 2
%16 = select i1 %14, i32 %15, i32 0
br label %17
17: ; preds = %9, %5, %2
%18 = phi i32 [ 0, %2 ], [ 0, %5 ], [ %16, %9 ]
ret i32 %18
}