#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 */
long long __ch2o_builtin_min(long long);
int __ch2o_len_core(int, long long, int);
int __ch2o_len_core_signed(int n, long long i, int w) {
  if (0 <= i) {
    return __ch2o_len_core(n, i, w);
  } else if (i == __ch2o_builtin_min((long long)0)) {
    return __ch2o_len_core(n, i, w);
  } else {
    return __ch2o_len_core(n, i * -1, w);
  }
}


x86 assembly (clang, -O0):
<__ch2o_len_core_signed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jg     1155 <__ch2o_len_core_signed+0x35>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <__ch2o_len_core@plt>
mov    %eax,-0x4(%rbp)
jmp    11a0 <__ch2o_len_core_signed+0x80>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <__ch2o_builtin_min@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
jne    118d <__ch2o_len_core_signed+0x6d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <__ch2o_len_core@plt>
mov    %eax,-0x4(%rbp)
jmp    11a0 <__ch2o_len_core_signed+0x80>
mov    -0x8(%rbp),%edi
imul   $0xffffffffffffffff,-0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <__ch2o_len_core@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__ch2o_len_core_signed>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
test   %rsi,%rsi
jns    1145 <__ch2o_len_core_signed+0x25>
xor    %edi,%edi
call   1030 <__ch2o_builtin_min@plt>
mov    %rbx,%rcx
neg    %rcx
cmp    %rbx,%rax
cmovne %rcx,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <__ch2o_len_core@plt>

LLVM IR (-O0):
define i32 @__ch2o_len_core_signed(i32 %0, i64 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
store i32 %0, i32* %5
store i64 %1, i64* %6
store i32 %2, i32* %7
%8 = load i64, i64* %6
%9 = icmp sle i64 0, %8
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load i32, i32* %5
%12 = load i64, i64* %6
%13 = load i32, i32* %7
%14 = call i32 @__ch2o_len_core(i32 %11, i64 %12, i32 %13)
store i32 %14, i32* %4
br label %30
15: ; preds = %3
%16 = load i64, i64* %6
%17 = call i64 @__ch2o_builtin_min(i64 0)
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32, i32* %5
%21 = load i64, i64* %6
%22 = load i32, i32* %7
%23 = call i32 @__ch2o_len_core(i32 %20, i64 %21, i32 %22)
store i32 %23, i32* %4
br label %30
24: ; preds = %15
%25 = load i32, i32* %5
%26 = load i64, i64* %6
%27 = mul nsw i64 %26, -1
%28 = load i32, i32* %7
%29 = call i32 @__ch2o_len_core(i32 %25, i64 %27, i32 %28)
store i32 %29, i32* %4
br label %30
30: ; preds = %24, %19, %10
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @__ch2o_len_core_signed(i32 %0, i64 %1, i32 %2) {
%4 = icmp sgt i64 %1, -1
br i1 %4, label %10, label %5
5: ; preds = %3
%6 = tail call i64 @__ch2o_builtin_min(i64 0)
%7 = icmp eq i64 %6, %1
%8 = sub nsw i64 0, %1
%9 = select i1 %7, i64 %1, i64 %8
br label %10
10: ; preds = %5, %3
%11 = phi i64 [ %1, %3 ], [ %9, %5 ]
%12 = tail call i32 @__ch2o_len_core(i32 %0, i64 %11, i32 %2)
ret i32 %12
}