#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 int int8_t;

/* Variables and functions */
int /*<<< orphan*/ ERANGE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ mx_strtoi8(char *, int *);
void test_mx_strtoi8(void) {
  int8_t u;
  assert(mx_strtoi8("127", &u) == 0);
  assert(u == 127);
  assert(mx_strtoi8("-127", &u) == 0);
  assert(u == -127);
  assert(mx_strtoi8(" -128", &u) == 0);
  assert(u == -128);
  assert(mx_strtoi8("128", &u) == -ERANGE);
  assert(mx_strtoi8("-129", &u) == -ERANGE);
}


x86 assembly (clang, -O0):
<test_mx_strtoi8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed2(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1030 <mx_strtoi8@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0x7f,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xea0(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1030 <mx_strtoi8@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0xffffff81,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe74(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1030 <mx_strtoi8@plt>
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
cmpl   $0xffffff80,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe45(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1030 <mx_strtoi8@plt>
xor    %ecx,%ecx
mov    0x2e14(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe1f(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1030 <mx_strtoi8@plt>
xor    %ecx,%ecx
mov    0x2dea(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_mx_strtoi8>:
push   %r14
push   %rbx
push   %rax
lea    0xed6(%rip),%rdi
lea    0x4(%rsp),%r14
mov    %r14,%rsi
call   1030 <mx_strtoi8@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpl   $0x7f,0x4(%rsp)
sete   %dil
call   1040 <assert@plt>
lea    0xea4(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoi8@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpl   $0xffffff81,0x4(%rsp)
sete   %dil
call   1040 <assert@plt>
lea    0xe7d(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoi8@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmpl   $0xffffff80,0x4(%rsp)
sete   %dil
call   1040 <assert@plt>
lea    0xe53(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoi8@plt>
mov    0x2e25(%rip),%rbx
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1040 <assert@plt>
lea    0xe34(%rip),%rdi
mov    %r14,%rsi
call   1030 <mx_strtoi8@plt>
xor    %edi,%edi
add    (%rbx),%eax
sete   %dil
call   1040 <assert@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"127\00"
@.str.1 = [5 x i8] c"-127\00"
@.str.2 = [6 x i8] c" -128\00"
@.str.3 = [4 x i8] c"128\00"
@ERANGE = global i32 0
@.str.4 = [5 x i8] c"-129\00"
define void @test_mx_strtoi8() {
%1 = alloca i32
%2 = call i32 @mx_strtoi8(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%3 = icmp eq i32 %2, 0
%4 = zext i1 %3 to i32
%5 = call i32 @assert(i32 %4)
%6 = load i32, i32* %1
%7 = icmp eq i32 %6, 127
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = call i32 @mx_strtoi8(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, -127
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = call i32 @mx_strtoi8(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %1
%23 = icmp eq i32 %22, -128
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = call i32 @mx_strtoi8(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%27 = load i32, i32* @ERANGE
%28 = sub nsw i32 0, %27
%29 = icmp eq i32 %26, %28
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = call i32 @mx_strtoi8(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%33 = load i32, i32* @ERANGE
%34 = sub nsw i32 0, %33
%35 = icmp eq i32 %32, %34
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"127\00"
@.str.1 = [5 x i8] c"-127\00"
@.str.2 = [6 x i8] c" -128\00"
@.str.3 = [4 x i8] c"128\00"
@ERANGE = global i32 0
@.str.4 = [5 x i8] c"-129\00"
define void @test_mx_strtoi8() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @mx_strtoi8(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i32 %3, 0
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 127
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i32 @mx_strtoi8(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%12 = icmp eq i32 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32, i32* %1
%16 = icmp eq i32 %15, -127
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i32 @mx_strtoi8(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %1
%24 = icmp eq i32 %23, -128
%25 = zext i1 %24 to i32
%26 = call i32 @assert(i32 %25)
%27 = call i32 @mx_strtoi8(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%28 = load i32, i32* @ERANGE
%29 = sub nsw i32 0, %28
%30 = icmp eq i32 %27, %29
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 @mx_strtoi8(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32* %1)
%34 = load i32, i32* @ERANGE
%35 = sub nsw i32 0, %34
%36 = icmp eq i32 %33, %35
%37 = zext i1 %36 to i32
%38 = call i32 @assert(i32 %37)
ret void
}