#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 */
int /*<<< orphan*/ printf(char *, char const *, size_t const, int, char *);
int str_to_int(char const *, char const **, size_t const);
void test_str_to_int(const char *str, const size_t base) {
  const char *endptr;
  int n = str_to_int(str, &endptr, base);
  printf("'%s' in base %zu converts to [%d] - *endptr is %s\n", str, base, n,
         *endptr ? "not zero" : "zero");
}


x86 assembly (clang, -O0):
<test_str_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rsi
call   1030 <str_to_int@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
lea    0xeda(%rip),%r8
lea    0xecf(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%r8
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_str_to_int>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    %r14,%rdx
call   1030 <str_to_int@plt>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
lea    0xef4(%rip),%rcx
lea    0xee9(%rip),%r8
cmove  %rcx,%r8
lea    0xeab(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %eax,%ecx
call   1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [51 x i8] c"'%s' in base %zu converts to [%d] - *endptr is %s\0A\00"
@.str.1 = [9 x i8] c"not zero\00"
@.str.2 = [5 x i8] c"zero\00"
define void @test_str_to_int(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
%8 = load i64, i64* %4
%9 = call i32 @str_to_int(i8* %7, i8** %5, i64 %8)
store i32 %9, i32* %6
%10 = load i8*, i8** %3
%11 = load i64, i64* %4
%12 = load i32, i32* %6
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
%19 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %10, i64 %11, i32 %12, i8* %18)
ret void
}

LLVM IR (-O2):
@.str = [51 x i8] c"'%s' in base %zu converts to [%d] - *endptr is %s\0A\00"
@.str.1 = [9 x i8] c"not zero\00"
@.str.2 = [5 x i8] c"zero\00"
define void @test_str_to_int(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32 @str_to_int(i8* %0, i8** %3, i64 %1)
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
%9 = select i1 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0)
%10 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1, i32 %5, i8* %9)
ret void
}