#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 */
typedef char wchar_t;
typedef int /*<<< orphan*/ uintmax_t;
typedef int /*<<< orphan*/ intmax_t;

/* Variables and functions */
int /*<<< orphan*/ ERANGE;
int /*<<< orphan*/ INTMAX_MAX;
int /*<<< orphan*/ INTMAX_MIN;
int /*<<< orphan*/ errno;
scalar_t__ iswspace(char const);
int /*<<< orphan*/ wcstoumax(char const *, char **, int);
intmax_t wcstoimax(const wchar_t *s, wchar_t **p, int base) {
  int sign = 0;
  uintmax_t x;
  for (; iswspace(*s); s++)
    ;
  if (*s == '-')
    sign = *s++;
  else if (*s == '+')
    s++;
  x = wcstoumax(s, p, base);
  if (x > INTMAX_MAX) {
    if (!sign || -x != INTMAX_MIN)
      errno = ERANGE;
    return sign ? INTMAX_MIN : INTMAX_MAX;
  }
  return sign ? -x : x;
}


x86 assembly (clang, -O0):
<wcstoimax>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <iswspace@plt>
cmp    $0x0,%rax
je     1166 <wcstoimax+0x46>
jmp    1155 <wcstoimax+0x35>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113a <wcstoimax+0x1a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    1190 <wcstoimax+0x70>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    11b1 <wcstoimax+0x91>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11ac <wcstoimax+0x8c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b1 <wcstoimax+0x91>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <wcstoumax@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%eax
jle    1238 <wcstoimax+0x118>
cmpl   $0x0,-0x20(%rbp)
je     11f4 <wcstoimax+0xd4>
xor    %eax,%eax
sub    -0x24(%rbp),%eax
mov    0x2df4(%rip),%rcx
cmp    (%rcx),%eax
je     1206 <wcstoimax+0xe6>
mov    0x2ddd(%rip),%rax
mov    (%rax),%ecx
mov    0x2dc4(%rip),%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x20(%rbp)
je     1221 <wcstoimax+0x101>
mov    0x2dc9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
jmp    122d <wcstoimax+0x10d>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <wcstoimax+0x13b>
cmpl   $0x0,-0x20(%rbp)
je     124f <wcstoimax+0x12f>
xor    %eax,%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1255 <wcstoimax+0x135>
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wcstoimax>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
nopl   (%rax)
movsbl 0x0(%rbp),%edi
call   1030 <iswspace@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1130 <wcstoimax+0x10>
mov    -0x1(%rbp),%al
cmp    $0x2b,%al
je     117d <wcstoimax+0x5d>
cmp    $0x2d,%al
jne    1179 <wcstoimax+0x59>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <wcstoumax@plt>
mov    %eax,%ecx
mov    0x2e84(%rip),%rdx
neg    %eax
cmp    (%rdx),%ecx
jle    11ac <wcstoimax+0x8c>
mov    0x2e6f(%rip),%rcx
mov    (%rcx),%ecx
cmp    %eax,%ecx
jne    1198 <wcstoimax+0x78>
jmp    11ac <wcstoimax+0x8c>
add    $0xffffffffffffffff,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <wcstoumax@plt>
mov    0x2e56(%rip),%rcx
mov    (%rcx),%ecx
cmp    %ecx,%eax
jle    11ac <wcstoimax+0x8c>
mov    0x2e39(%rip),%rax
mov    (%rax),%eax
mov    0x2e20(%rip),%rdx
mov    %eax,(%rdx)
mov    %ecx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@INTMAX_MAX = global i32 0
@INTMAX_MIN = global i32 0
@ERANGE = global i32 0
@errno = global i32 0
define i32 @wcstoimax(i8* %0, i8** %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %16, %3
%11 = load i8*, i8** %5
%12 = load i8, i8* %11
%13 = call i64 @iswspace(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10
br label %16
16: ; preds = %15
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %5
br label %10
19: ; preds = %10
%20 = load i8*, i8** %5
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 45
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
%27 = load i8, i8* %25
%28 = sext i8 %27 to i32
store i32 %28, i32* %8
br label %38
29: ; preds = %19
%30 = load i8*, i8** %5
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 43
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = load i8*, i8** %5
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %5
br label %37
37: ; preds = %34, %29
br label %38
38: ; preds = %37, %24
%39 = load i8*, i8** %5
%40 = load i8**, i8*** %6
%41 = load i32, i32* %7
%42 = call i32 @wcstoumax(i8* %39, i8** %40, i32 %41)
store i32 %42, i32* %9
%43 = load i32, i32* %9
%44 = load i32, i32* @INTMAX_MAX
%45 = icmp sgt i32 %43, %44
br i1 %45, label %46, label %65
46: ; preds = %38
%47 = load i32, i32* %8
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %54
49: ; preds = %46
%50 = load i32, i32* %9
%51 = sub nsw i32 0, %50
%52 = load i32, i32* @INTMAX_MIN
%53 = icmp ne i32 %51, %52
br i1 %53, label %54, label %56
54: ; preds = %49, %46
%55 = load i32, i32* @ERANGE
store i32 %55, i32* @errno
br label %56
56: ; preds = %54, %49
%57 = load i32, i32* %8
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = load i32, i32* @INTMAX_MIN
br label %63
61: ; preds = %56
%62 = load i32, i32* @INTMAX_MAX
br label %63
63: ; preds = %61, %59
%64 = phi i32 [ %60, %59 ], [ %62, %61 ]
store i32 %64, i32* %4
br label %75
65: ; preds = %38
%66 = load i32, i32* %8
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i32, i32* %9
%70 = sub nsw i32 0, %69
br label %73
71: ; preds = %65
%72 = load i32, i32* %9
br label %73
73: ; preds = %71, %68
%74 = phi i32 [ %70, %68 ], [ %72, %71 ]
store i32 %74, i32* %4
br label %75
75: ; preds = %73, %63
%76 = load i32, i32* %4
ret i32 %76
}

LLVM IR (-O2):
@INTMAX_MAX = global i32 0
@INTMAX_MIN = global i32 0
@ERANGE = global i32 0
@errno = global i32 0
define i32 @wcstoimax(i8* %0, i8** %1, i32 %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i8* [ %0, %3 ], [ %9, %4 ]
%6 = load i8, i8* %5
%7 = tail call i64 @iswspace(i8 signext %6)
%8 = icmp eq i64 %7, 0
%9 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %8, label %10, label %4
10: ; preds = %4
%11 = load i8, i8* %5
switch i8 %11, label %13 [
i8 45, label %18
i8 43, label %12
]
12: ; preds = %10
br label %13
13: ; preds = %10, %12
%14 = phi i8* [ %9, %12 ], [ %5, %10 ]
%15 = tail call i32 @wcstoumax(i8* %14, i8** %1, i32 %2)
%16 = load i32, i32* @INTMAX_MAX
%17 = icmp sgt i32 %15, %16
br i1 %17, label %26, label %29
18: ; preds = %10
%19 = tail call i32 @wcstoumax(i8* %9, i8** %1, i32 %2)
%20 = load i32, i32* @INTMAX_MAX
%21 = icmp sle i32 %19, %20
%22 = sub nsw i32 0, %19
%23 = load i32, i32* @INTMAX_MIN
%24 = icmp eq i32 %23, %22
%25 = select i1 %21, i1 true, i1 %24
br i1 %25, label %29, label %26
26: ; preds = %18, %13
%27 = phi i32 [ %16, %13 ], [ %23, %18 ]
%28 = load i32, i32* @ERANGE
store i32 %28, i32* @errno
br label %29
29: ; preds = %26, %18, %13
%30 = phi i32 [ %15, %13 ], [ %22, %18 ], [ %27, %26 ]
ret i32 %30
}