#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*/ memcpy(char *, char const *, int);
int strtol(char *, char **, int);
int nmea_atoi(const char *str, int str_sz, int radix) {
  char *tmp_ptr;
  char buff[128];
  int res = 0;
  if (str_sz < 128) {
    memcpy(&buff[0], str, str_sz);
    buff[str_sz] = '\0';
    res = strtol(&buff[0], &tmp_ptr, radix);
  }
  return res;
}


x86 assembly (clang, -O0):
<nmea_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0xa4(%rbp)
cmpl   $0x80,-0xc(%rbp)
jge    1184 <nmea_atoi+0x64>
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1040 <memcpy@plt>
movslq -0xc(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    -0x18(%rbp),%rsi
call   1030 <strtol@plt>
mov    %eax,-0xa4(%rbp)
mov    -0xa4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nmea_atoi>:
push   %rbp
push   %r14
push   %rbx
sub    $0x90,%rsp
mov    %esi,%ebp
xor    %eax,%eax
cmp    $0x7f,%esi
jg     115f <nmea_atoi+0x3f>
mov    %edx,%ebx
mov    %rdi,%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1030 <strtol@plt>
add    $0x90,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @nmea_atoi(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [128 x i8]
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %9
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 128
br i1 %11, label %12, label %23
12: ; preds = %3
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = call i32 @memcpy(i8* %13, i8* %14, i32 %15)
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%21 = load i32, i32* %6
%22 = call i32 @strtol(i8* %20, i8** %7, i32 %21)
store i32 %22, i32* %9
br label %23
23: ; preds = %12, %3
%24 = load i32, i32* %9
ret i32 %24
}

LLVM IR (-O2):
define i32 @nmea_atoi(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca [128 x i8]
%6 = bitcast i8** %4 to i8*
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%8 = icmp slt i32 %1, 128
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = call i32 @memcpy(i8* %7, i8* %0, i32 %1)
%11 = sext i32 %1 to i64
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 %11
store i8 0, i8* %12
%13 = call i32 @strtol(i8* %7, i8** %4, i32 %2)
br label %14
14: ; preds = %9, %3
%15 = phi i32 [ %13, %9 ], [ 0, %3 ]
ret i32 %15
}