#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 atoi(char *);
scalar_t__ isdigit(char);
char *sgetint(char *sp, int *num) {
  char s[10] = "", *p = s;
  for (; isdigit(*sp); *p++ = *sp++)
    ;
  *num = atoi(s);
  return s[0] == '\0' ? NULL : ++sp;
}


x86 assembly (clang, -O0):
<sgetint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1a(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
lea    -0x1a(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     119a <sgetint+0x6a>
jmp    1173 <sgetint+0x43>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    1158 <sgetint+0x28>
lea    -0x1a(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movsbl -0x1a(%rbp),%eax
cmp    $0x0,%eax
jne    11c3 <sgetint+0x93>
xor    %eax,%eax
mov    %rax,-0x30(%rbp)
jmp    11d3 <sgetint+0xa3>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sgetint>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movw   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1191 <sgetint+0x71>
mov    %rsp,%rbx
add    $0x1,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl -0x1(%r15),%eax
mov    %al,(%rbx)
add    $0x1,%rbx
movsbl (%r15),%edi
call   1030 <isdigit@plt>
add    $0x1,%r15
test   %rax,%rax
jne    1160 <sgetint+0x40>
mov    (%rsp),%bl
mov    %rsp,%rdi
call   1040 <atoi@plt>
mov    %eax,(%r14)
test   %bl,%bl
jne    119f <sgetint+0x7f>
jmp    119c <sgetint+0x7c>
mov    %rsp,%rdi
call   1040 <atoi@plt>
mov    %eax,(%r14)
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @sgetint(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [10 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = bitcast [10 x i8]* %5 to i8*
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
store i8* %8, i8** %6
br label %9
9: ; preds = %15, %2
%10 = load i8*, i8** %3
%11 = load i8, i8* %10
%12 = call i64 @isdigit(i8 signext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %9
br label %15
15: ; preds = %14
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %3
%18 = load i8, i8* %16
%19 = load i8*, i8** %6
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %6
store i8 %18, i8* %19
br label %9
21: ; preds = %9
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%23 = call i32 @atoi(i8* %22)
%24 = load i32*, i32** %4
store i32 %23, i32* %24
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %21
br label %33
30: ; preds = %21
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %3
br label %33
33: ; preds = %30, %29
%34 = phi i8* [ null, %29 ], [ %32, %30 ]
ret i8* %34
}

LLVM IR (-O2):
define i8* @sgetint(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = load i8, i8* %0
%6 = tail call i64 @isdigit(i8 signext %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @atoi(i8* %4)
store i32 %9, i32* %1
br label %24
10: ; preds = %2, %10
%11 = phi i8* [ %15, %10 ], [ %4, %2 ]
%12 = phi i8* [ %13, %10 ], [ %0, %2 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %12
%15 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %14, i8* %11
%16 = load i8, i8* %13
%17 = tail call i64 @isdigit(i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %10
19: ; preds = %10
%20 = load i8, i8* %4
%21 = icmp eq i8 %20, 0
%22 = call i32 @atoi(i8* %4)
store i32 %22, i32* %1
%23 = getelementptr inbounds i8, i8* %12, i64 2
br i1 %21, label %24, label %25
24: ; preds = %8, %19
br label %25
25: ; preds = %19, %24
%26 = phi i8* [ null, %24 ], [ %23, %19 ]
ret i8* %26
}