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

/* Variables and functions */
char jx_getchar(struct jx_parser *);
int /*<<< orphan*/ jx_parse_error(struct jx_parser *, char *);
scalar_t__ sscanf(char *, char *, int *);
int jx_scan_unicode(struct jx_parser *s) {
  int i;
  char str[5];
  for (i = 0; i < 4; i++) {
    str[i] = jx_getchar(s);
  }
  str[4] = 0;
  int uc;
  if (sscanf(str, "%x", &uc)) {
    if (uc <= 0x7f) {
      return uc;
    } else {
      jx_parse_error(s, "unsupported unicode escape string");
      return -1;
    }
  } else {
    jx_parse_error(s, "invalid unicode escape string");
    return -1;
  }
}


x86 assembly (clang, -O0):
<jx_scan_unicode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    116e <jx_scan_unicode+0x3e>
mov    -0x10(%rbp),%rdi
call   1030 <jx_getchar@plt>
mov    %al,%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x19(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <jx_scan_unicode+0x13>
movb   $0x0,-0x15(%rbp)
lea    -0x19(%rbp),%rdi
lea    0xe83(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x0,%rax
je     11c1 <jx_scan_unicode+0x91>
cmpl   $0x7f,-0x20(%rbp)
jg     11a5 <jx_scan_unicode+0x75>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d8 <jx_scan_unicode+0xa8>
mov    -0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
call   1050 <jx_parse_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d8 <jx_scan_unicode+0xa8>
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1050 <jx_parse_error@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jx_scan_unicode>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1030 <jx_getchar@plt>
mov    %al,0x7(%rsp)
mov    %rbx,%rdi
call   1030 <jx_getchar@plt>
mov    %al,0x8(%rsp)
mov    %rbx,%rdi
call   1030 <jx_getchar@plt>
mov    %al,0x9(%rsp)
mov    %rbx,%rdi
call   1030 <jx_getchar@plt>
mov    %al,0xa(%rsp)
movb   $0x0,0xb(%rsp)
lea    0xe8f(%rip),%rsi
lea    0x7(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   1040 <sscanf@plt>
test   %rax,%rax
je     1199 <jx_scan_unicode+0x69>
mov    0xc(%rsp),%eax
cmp    $0x80,%eax
jl     11ad <jx_scan_unicode+0x7d>
lea    0xe6c(%rip),%rsi
jmp    11a0 <jx_scan_unicode+0x70>
lea    0xe85(%rip),%rsi
mov    %rbx,%rdi
call   1050 <jx_parse_error@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.jx_parser = type { i32 }
@.str = [3 x i8] c"%x\00"
@.str.1 = [34 x i8] c"unsupported unicode escape string\00"
@.str.2 = [30 x i8] c"invalid unicode escape string\00"
define i32 @jx_scan_unicode(%struct.jx_parser* %0) {
%2 = alloca i32
%3 = alloca %struct.jx_parser*
%4 = alloca i32
%5 = alloca [5 x i8]
%6 = alloca i32
store %struct.jx_parser* %0, %struct.jx_parser** %3
store i32 0, i32* %4
br label %7
7: ; preds = %16, %1
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load %struct.jx_parser*, %struct.jx_parser** %3
%12 = call signext i8 @jx_getchar(%struct.jx_parser* %11)
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 %14
store i8 %12, i8* %15
br label %16
16: ; preds = %10
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %7
19: ; preds = %7
%20 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 4
store i8 0, i8* %20
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%22 = call i64 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i32, i32* %6
%26 = icmp sle i32 %25, 127
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load i32, i32* %6
store i32 %28, i32* %2
br label %35
29: ; preds = %24
%30 = load %struct.jx_parser*, %struct.jx_parser** %3
%31 = call i32 @jx_parse_error(%struct.jx_parser* %30, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %35
32: ; preds = %19
%33 = load %struct.jx_parser*, %struct.jx_parser** %3
%34 = call i32 @jx_parse_error(%struct.jx_parser* %33, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %35
35: ; preds = %32, %29, %27
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
%struct.jx_parser = type { i32 }
@.str = [3 x i8] c"%x\00"
@.str.1 = [34 x i8] c"unsupported unicode escape string\00"
@.str.2 = [30 x i8] c"invalid unicode escape string\00"
define i32 @jx_scan_unicode(%struct.jx_parser* %0) {
%2 = alloca [5 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%5 = tail call signext i8 @jx_getchar(%struct.jx_parser* %0)
store i8 %5, i8* %4
%6 = tail call signext i8 @jx_getchar(%struct.jx_parser* %0)
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 1
store i8 %6, i8* %7
%8 = tail call signext i8 @jx_getchar(%struct.jx_parser* %0)
%9 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 2
store i8 %8, i8* %9
%10 = tail call signext i8 @jx_getchar(%struct.jx_parser* %0)
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 3
store i8 %10, i8* %11
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 4
store i8 0, i8* %12
%13 = bitcast i32* %3 to i8*
%14 = call i64 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %1
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 128
br i1 %18, label %22, label %19
19: ; preds = %1, %16
%20 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), %16 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), %1 ]
%21 = call i32 @jx_parse_error(%struct.jx_parser* %0, i8* %20)
br label %22
22: ; preds = %19, %16
%23 = phi i32 [ %17, %16 ], [ -1, %19 ]
ret i32 %23
}