#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 */
scalar_t__ ucs_from_4hex(unsigned char *, unsigned int *);
int next_surrogate_end(unsigned char *str) {
  unsigned char *src = str;
  src += 4;
  if (*src == '\\') {
    unsigned hval;
    src++;
    if (*src == 'u') {
      src++;
      if (ucs_from_4hex(src, &hval)) {
        if ((0xDC00 <= hval) && (hval <= 0xDFFF)) {
          return hval;
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<next_surrogate_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x5c,%eax
jne    11b4 <next_surrogate_end+0xa4>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x75,%eax
jne    11af <next_surrogate_end+0x9f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1030 <ucs_from_4hex@plt>
cmp    $0x0,%rax
je     11aa <next_surrogate_end+0x9a>
mov    $0xdc00,%eax
cmp    -0x1c(%rbp),%eax
ja     11a5 <next_surrogate_end+0x95>
cmpl   $0xdfff,-0x1c(%rbp)
ja     11a5 <next_surrogate_end+0x95>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bb <next_surrogate_end+0xab>
jmp    11aa <next_surrogate_end+0x9a>
jmp    11af <next_surrogate_end+0x9f>
jmp    11b4 <next_surrogate_end+0xa4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<next_surrogate_end>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
cmpb   $0x5c,0x4(%rdi)
jne    114c <next_surrogate_end+0x3c>
cmpb   $0x75,0x5(%rdi)
jne    114c <next_surrogate_end+0x3c>
add    $0x6,%rdi
lea    0xc(%rsp),%rsi
call   1030 <ucs_from_4hex@plt>
test   %rax,%rax
je     114c <next_surrogate_end+0x3c>
mov    0xc(%rsp),%eax
mov    %eax,%ecx
and    $0xfffffc00,%ecx
cmp    $0xdc00,%ecx
jne    114c <next_surrogate_end+0x3c>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @next_surrogate_end(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i64 4
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = icmp eq i32 %11, 92
br i1 %12, label %13, label %37
13: ; preds = %1
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %18, 117
br i1 %19, label %20, label %36
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %4
%23 = load i8*, i8** %4
%24 = call i64 @ucs_from_4hex(i8* %23, i32* %5)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %20
%27 = load i32, i32* %5
%28 = icmp ule i32 56320, %27
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i32, i32* %5
%31 = icmp ule i32 %30, 57343
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = load i32, i32* %5
store i32 %33, i32* %2
br label %38
34: ; preds = %29, %26
br label %35
35: ; preds = %34, %20
br label %36
36: ; preds = %35, %13
br label %37
37: ; preds = %36, %1
store i32 0, i32* %2
br label %38
38: ; preds = %37, %32
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
define i32 @next_surrogate_end(i8* %0) {
%2 = alloca i32
%3 = getelementptr inbounds i8, i8* %0, i64 4
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 92
br i1 %5, label %6, label %21
6: ; preds = %1
%7 = bitcast i32* %2 to i8*
%8 = getelementptr inbounds i8, i8* %0, i64 5
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 117
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %0, i64 6
%13 = call i64 @ucs_from_4hex(i8* %12, i32* %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i32, i32* %2
%17 = and i32 %16, -1024
%18 = icmp eq i32 %17, 56320
br i1 %18, label %20, label %19
19: ; preds = %6, %15, %11
br label %21
20: ; preds = %15
br label %21
21: ; preds = %1, %19, %20
%22 = phi i32 [ %16, %20 ], [ 0, %19 ], [ 0, %1 ]
ret i32 %22
}