#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 *);
int convertCharToInt(char *data) {
  int number;
  if (data == NULL)
    return -1;
  if ((*data) == '0') {
    if (*(data + 1) == '\0') {
      return 0;
    } else
      return -1;
  }
  number = atoi(data);
  if (number > 0)
    return number;
  else
    return -1;
}


x86 assembly (clang, -O0):
<convertCharToInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1133 <convertCharToInt+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    1194 <convertCharToInt+0x84>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    116c <convertCharToInt+0x5c>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    1160 <convertCharToInt+0x50>
movl   $0x0,-0x4(%rbp)
jmp    1194 <convertCharToInt+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    1194 <convertCharToInt+0x84>
mov    -0x10(%rbp),%rdi
call   1030 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    118d <convertCharToInt+0x7d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <convertCharToInt+0x84>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convertCharToInt>:
push   %rax
test   %rdi,%rdi
je     1124 <convertCharToInt+0x14>
cmpb   $0x30,(%rdi)
jne    112b <convertCharToInt+0x1b>
xor    %eax,%eax
cmp    0x1(%rdi),%al
sbb    %eax,%eax
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret
call   1030 <atoi@plt>
mov    %eax,%ecx
test   %eax,%eax
mov    $0xffffffff,%eax
cmovg  %ecx,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
define i32 @convertCharToInt(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %15, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 48
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = icmp ne i8 %8, 0
%10 = sext i1 %9 to i32
br label %15
11: ; preds = %3
%12 = tail call i32 @atoi(i8* %0)
%13 = icmp sgt i32 %12, 0
%14 = select i1 %13, i32 %12, i32 -1
br label %15
15: ; preds = %11, %6, %1
%16 = phi i32 [ -1, %1 ], [ %10, %6 ], [ %14, %11 ]
ret i32 %16
}