#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__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void check_endptr(char *endptr, char *input) {
  if (errno != 0) {
    perror(input);
    exit(-1);
  }
  if (*endptr != 0) {
    fprintf(stderr, "%s: bad format\n", input);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<check_endptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e91(%rip),%rax
cmpq   $0x0,(%rax)
je     1164 <check_endptr+0x34>
mov    -0x10(%rbp),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1197 <check_endptr+0x67>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe78(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_endptr>:
push   %rax
mov    %rsi,%rdx
mov    0x2e9d(%rip),%rax
cmpq   $0x0,(%rax)
jne    1148 <check_endptr+0x18>
cmpb   $0x0,(%rdi)
jne    115a <check_endptr+0x2a>
pop    %rax
ret
mov    %rdx,%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [16 x i8] c"%s: bad format\0A\00"
define void @check_endptr(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%5 = load i64, i64* @errno
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i8*, i8** %4
%9 = call i32 @perror(i8* %8)
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %4
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %11
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [16 x i8] c"%s: bad format\0A\00"
define void @check_endptr(i8* nocapture %0, i8* %1) {
%3 = load i64, i64* @errno
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @perror(i8* %1)
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %2
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %8
ret void
}