#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 */
typedef int /*<<< orphan*/ err;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ str_to_int(char *, int, int *, char *, int);
int test_str_to_int(void) {
  int i;
  char err[512] = {0};
  err[0] = '\0';
  str_to_int("123", 10, &i, err, sizeof(err));
  do {
    int __my_ret__ = err[0];
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 25, "err[0]");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    if (i != 123) {
      fprintf(stderr, "failed on line %d: %s\n", 26, "i");
      return 1;
    }
  } while (0);
  ;
  err[0] = '\0';
  str_to_int("0", 10, &i, err, sizeof(err));
  do {
    int __my_ret__ = err[0];
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 30, "err[0]");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    if (i != 0) {
      fprintf(stderr, "failed on line %d: %s\n", 31, "i");
      return 1;
    }
  } while (0);
  ;
  err[0] = '\0';
  str_to_int("", 10, &i, err, sizeof(err));
  do {
    int __my_ret__ = err[0];
    if (__my_ret__ == 0) {
      fprintf(stderr, "failed on line %d: %s\n", 35, "err[0]");
      return -1;
    }
  } while (0);
  ;
  err[0] = '\0';
  str_to_int("10b", 10, &i, err, sizeof(err));
  do {
    int __my_ret__ = err[0];
    if (__my_ret__ == 0) {
      fprintf(stderr, "failed on line %d: %s\n", 39, "err[0]");
      return -1;
    }
  } while (0);
  ;
  err[0] = '\0';
  str_to_int("f", 16, &i, err, sizeof(err));
  do {
    int __my_ret__ = err[0];
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 43, "err[0]");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    if (i != 15) {
      fprintf(stderr, "failed on line %d: %s\n", 44, "i");
      return 1;
    }
  } while (0);
  ;
  err[0] = '\0';
  str_to_int("8589934592", 10, &i, err, sizeof(err));
  do {
    int __my_ret__ = err[0];
    if (__my_ret__ == 0) {
      fprintf(stderr, "failed on line %d: %s\n", 48, "err[0]");
      return -1;
    }
  } while (0);
  ;
  err[0] = '\0';
  str_to_int("2147483647", 10, &i, err, sizeof(err));
  do {
    int __my_ret__ = err[0];
    if (__my_ret__) {
      fprintf(stderr, "failed on line %d: %s\n", 52, "err[0]");
      return __my_ret__;
    }
  } while (0);
  ;
  do {
    if (i != 2147483647) {
      fprintf(stderr, "failed on line %d: %s\n", 53, "i");
      return 1;
    }
  } while (0);
  ;
  err[0] = '\0';
  str_to_int("blah", 10, &i, err, sizeof(err));
  do {
    int __my_ret__ = err[0];
    if (__my_ret__ == 0) {
      fprintf(stderr, "failed on line %d: %s\n", 57, "err[0]");
      return -1;
    }
  } while (0);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<test_str_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
movb   $0x0,-0x210(%rbp)
lea    -0x210(%rbp),%rcx
lea    0xe9d(%rip),%rdi
mov    $0xa,%esi
lea    -0x8(%rbp),%rdx
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl -0x210(%rbp),%eax
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
je     11c0 <test_str_to_int+0x90>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
mov    $0x19,%edx
lea    0xe6e(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x214(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    11c5 <test_str_to_int+0x95>
jmp    11ca <test_str_to_int+0x9a>
cmpl   $0x7b,-0x8(%rbp)
je     1201 <test_str_to_int+0xd1>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
mov    $0x1a,%edx
lea    0xe32(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    1206 <test_str_to_int+0xd6>
movb   $0x0,-0x210(%rbp)
lea    -0x210(%rbp),%rcx
lea    0xe09(%rip),%rdi
mov    $0xa,%esi
lea    -0x8(%rbp),%rdx
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl -0x210(%rbp),%eax
mov    %eax,-0x218(%rbp)
cmpl   $0x0,-0x218(%rbp)
je     1278 <test_str_to_int+0x148>
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
mov    $0x1e,%edx
lea    0xdb6(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x218(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    127d <test_str_to_int+0x14d>
jmp    1282 <test_str_to_int+0x152>
cmpl   $0x0,-0x8(%rbp)
je     12b9 <test_str_to_int+0x189>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
mov    $0x1f,%edx
lea    0xd7a(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    12be <test_str_to_int+0x18e>
movb   $0x0,-0x210(%rbp)
lea    -0x210(%rbp),%rcx
lea    0xd47(%rip),%rdi
mov    $0xa,%esi
lea    -0x8(%rbp),%rdx
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl -0x210(%rbp),%eax
mov    %eax,-0x21c(%rbp)
cmpl   $0x0,-0x21c(%rbp)
jne    132e <test_str_to_int+0x1fe>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
lea    0xcf3(%rip),%rsi
mov    $0x23,%edx
lea    0xcfe(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    1333 <test_str_to_int+0x203>
movb   $0x0,-0x210(%rbp)
lea    -0x210(%rbp),%rcx
lea    0xcde(%rip),%rdi
mov    $0xa,%esi
lea    -0x8(%rbp),%rdx
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl -0x210(%rbp),%eax
mov    %eax,-0x220(%rbp)
cmpl   $0x0,-0x220(%rbp)
jne    13a3 <test_str_to_int+0x273>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
lea    0xc7e(%rip),%rsi
mov    $0x27,%edx
lea    0xc89(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    13a8 <test_str_to_int+0x278>
movb   $0x0,-0x210(%rbp)
lea    -0x210(%rbp),%rcx
lea    0xc6d(%rip),%rdi
mov    $0x10,%esi
lea    -0x8(%rbp),%rdx
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl -0x210(%rbp),%eax
mov    %eax,-0x224(%rbp)
cmpl   $0x0,-0x224(%rbp)
je     141a <test_str_to_int+0x2ea>
mov    0x2bee(%rip),%rax
mov    (%rax),%edi
lea    0xc09(%rip),%rsi
mov    $0x2b,%edx
lea    0xc14(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x224(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    141f <test_str_to_int+0x2ef>
jmp    1424 <test_str_to_int+0x2f4>
cmpl   $0xf,-0x8(%rbp)
je     145b <test_str_to_int+0x32b>
mov    0x2bab(%rip),%rax
mov    (%rax),%edi
lea    0xbc6(%rip),%rsi
mov    $0x2c,%edx
lea    0xbd8(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    1460 <test_str_to_int+0x330>
movb   $0x0,-0x210(%rbp)
lea    -0x210(%rbp),%rcx
lea    0xbb7(%rip),%rdi
mov    $0xa,%esi
lea    -0x8(%rbp),%rdx
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl -0x210(%rbp),%eax
mov    %eax,-0x228(%rbp)
cmpl   $0x0,-0x228(%rbp)
jne    14d0 <test_str_to_int+0x3a0>
mov    0x2b36(%rip),%rax
mov    (%rax),%edi
lea    0xb51(%rip),%rsi
mov    $0x30,%edx
lea    0xb5c(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    14d5 <test_str_to_int+0x3a5>
movb   $0x0,-0x210(%rbp)
lea    -0x210(%rbp),%rcx
lea    0xb4d(%rip),%rdi
mov    $0xa,%esi
lea    -0x8(%rbp),%rdx
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl -0x210(%rbp),%eax
mov    %eax,-0x22c(%rbp)
cmpl   $0x0,-0x22c(%rbp)
je     1547 <test_str_to_int+0x417>
mov    0x2ac1(%rip),%rax
mov    (%rax),%edi
lea    0xadc(%rip),%rsi
mov    $0x34,%edx
lea    0xae7(%rip),%rcx
call   1050 <fprintf@plt>
mov    -0x22c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    154c <test_str_to_int+0x41c>
jmp    1551 <test_str_to_int+0x421>
cmpl   $0x7fffffff,-0x8(%rbp)
je     158b <test_str_to_int+0x45b>
mov    0x2a7b(%rip),%rax
mov    (%rax),%edi
lea    0xa96(%rip),%rsi
mov    $0x35,%edx
lea    0xaa8(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    1590 <test_str_to_int+0x460>
movb   $0x0,-0x210(%rbp)
lea    -0x210(%rbp),%rcx
lea    0xa9d(%rip),%rdi
mov    $0xa,%esi
lea    -0x8(%rbp),%rdx
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl -0x210(%rbp),%eax
mov    %eax,-0x230(%rbp)
cmpl   $0x0,-0x230(%rbp)
jne    1600 <test_str_to_int+0x4d0>
mov    0x2a06(%rip),%rax
mov    (%rax),%edi
lea    0xa21(%rip),%rsi
mov    $0x39,%edx
lea    0xa2c(%rip),%rcx
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    160c <test_str_to_int+0x4dc>
jmp    1605 <test_str_to_int+0x4d5>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_str_to_int>:
push   %rbx
sub    $0x210,%rsp
lea    0x10(%rsp),%rbx
mov    $0x200,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xead(%rip),%rdi
lea    0xc(%rsp),%rdx
mov    $0xa,%esi
mov    %rbx,%rcx
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl 0x10(%rsp),%ebx
test   %ebx,%ebx
je     1197 <test_str_to_int+0x67>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
lea    0xe90(%rip),%rcx
mov    $0x19,%edx
call   1050 <fprintf@plt>
jmp    1216 <test_str_to_int+0xe6>
cmpl   $0x7b,0xc(%rsp)
jne    11f0 <test_str_to_int+0xc0>
movb   $0x0,0x10(%rsp)
lea    0xe7a(%rip),%rdi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0xa,%esi
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl 0x10(%rsp),%ebx
test   %ebx,%ebx
je     1221 <test_str_to_int+0xf1>
mov    0x2e0c(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
lea    0xe37(%rip),%rcx
mov    $0x1e,%edx
call   1050 <fprintf@plt>
jmp    1216 <test_str_to_int+0xe6>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
lea    0xe1b(%rip),%rcx
mov    $0x1a,%edx
call   1050 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x210,%rsp
pop    %rbx
ret
cmpl   $0x0,0xc(%rsp)
je     1246 <test_str_to_int+0x116>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
lea    0xde3(%rip),%rcx
mov    $0x1f,%edx
jmp    120c <test_str_to_int+0xdc>
movb   $0x0,0x10(%rsp)
lea    0xdc8(%rip),%rdi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0xa,%esi
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
cmpb   $0x0,0x10(%rsp)
je     12f9 <test_str_to_int+0x1c9>
movb   $0x0,0x10(%rsp)
lea    0xda3(%rip),%rdi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0xa,%esi
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
cmpb   $0x0,0x10(%rsp)
je     1317 <test_str_to_int+0x1e7>
movb   $0x0,0x10(%rsp)
lea    0xd7a(%rip),%rdi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0x10,%esi
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl 0x10(%rsp),%ebx
test   %ebx,%ebx
je     1342 <test_str_to_int+0x212>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
lea    0xd21(%rip),%rsi
lea    0xd31(%rip),%rcx
mov    $0x2b,%edx
call   1050 <fprintf@plt>
jmp    1216 <test_str_to_int+0xe6>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
lea    0xd0b(%rip),%rcx
mov    $0x23,%edx
jmp    1333 <test_str_to_int+0x203>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
lea    0xcdd(%rip),%rsi
lea    0xced(%rip),%rcx
mov    $0x27,%edx
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1216 <test_str_to_int+0xe6>
cmpl   $0xf,0xc(%rsp)
jne    13cf <test_str_to_int+0x29f>
movb   $0x0,0x10(%rsp)
lea    0xcd3(%rip),%rdi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0xa,%esi
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
cmpb   $0x0,0x10(%rsp)
je     13f0 <test_str_to_int+0x2c0>
movb   $0x0,0x10(%rsp)
lea    0xcb1(%rip),%rdi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0xa,%esi
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
movsbl 0x10(%rsp),%ebx
test   %ebx,%ebx
je     1411 <test_str_to_int+0x2e1>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
lea    0xc4b(%rip),%rsi
lea    0xc5b(%rip),%rcx
mov    $0x34,%edx
call   1050 <fprintf@plt>
jmp    1216 <test_str_to_int+0xe6>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
lea    0xc25(%rip),%rsi
lea    0xc3c(%rip),%rcx
mov    $0x2c,%edx
jmp    120c <test_str_to_int+0xdc>
mov    0x2be9(%rip),%rax
mov    (%rax),%edi
lea    0xc04(%rip),%rsi
lea    0xc14(%rip),%rcx
mov    $0x30,%edx
jmp    1333 <test_str_to_int+0x203>
cmpl   $0x7fffffff,0xc(%rsp)
7f
jne    146f <test_str_to_int+0x33f>
movb   $0x0,0x10(%rsp)
lea    0xc1b(%rip),%rdi
lea    0xc(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    $0xa,%esi
mov    $0x200,%r8d
call   1030 <str_to_int@plt>
xor    %ebx,%ebx
cmpb   $0x0,0x10(%rsp)
jne    1216 <test_str_to_int+0xe6>
mov    0x2b8b(%rip),%rax
mov    (%rax),%edi
lea    0xba6(%rip),%rsi
lea    0xbb6(%rip),%rcx
mov    $0x39,%edx
jmp    1333 <test_str_to_int+0x203>
mov    0x2b6a(%rip),%rax
mov    (%rax),%edi
lea    0xb85(%rip),%rsi
lea    0xb9c(%rip),%rcx
mov    $0x35,%edx
jmp    120c <test_str_to_int+0xdc>

LLVM IR (-O0):
@.str = [4 x i8] c"123\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [7 x i8] c"err[0]\00"
@.str.3 = [2 x i8] c"i\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [4 x i8] c"10b\00"
@.str.7 = [2 x i8] c"f\00"
@.str.8 = [11 x i8] c"8589934592\00"
@.str.9 = [11 x i8] c"2147483647\00"
@.str.10 = [5 x i8] c"blah\00"
define i32 @test_str_to_int() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = bitcast [512 x i8]* %3 to i8*
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i8 0, i8* %13
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%15 = call i32 @str_to_int(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 10, i32* %2, i8* %14, i32 512)
br label %16
16: ; preds = %0
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* %4
store i32 %25, i32* %1
br label %161
26: ; preds = %16
br label %27
27: ; preds = %26
br label %28
28: ; preds = %27
%29 = load i32, i32* %2
%30 = icmp ne i32 %29, 123
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %161
34: ; preds = %28
br label %35
35: ; preds = %34
%36 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i8 0, i8* %36
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%38 = call i32 @str_to_int(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 10, i32* %2, i8* %37, i32 512)
br label %39
39: ; preds = %35
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
store i32 %42, i32* %5
%43 = load i32, i32* %5
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%48 = load i32, i32* %5
store i32 %48, i32* %1
br label %161
49: ; preds = %39
br label %50
50: ; preds = %49
br label %51
51: ; preds = %50
%52 = load i32, i32* %2
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %161
57: ; preds = %51
br label %58
58: ; preds = %57
%59 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i8 0, i8* %59
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%61 = call i32 @str_to_int(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 10, i32* %2, i8* %60, i32 512)
br label %62
62: ; preds = %58
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
store i32 %65, i32* %6
%66 = load i32, i32* %6
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %62
%69 = load i32, i32* @stderr
%70 = call i32 @fprintf(i32 %69, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %161
71: ; preds = %62
br label %72
72: ; preds = %71
%73 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i8 0, i8* %73
%74 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%75 = call i32 @str_to_int(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 10, i32* %2, i8* %74, i32 512)
br label %76
76: ; preds = %72
%77 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
store i32 %79, i32* %7
%80 = load i32, i32* %7
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %76
%83 = load i32, i32* @stderr
%84 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %161
85: ; preds = %76
br label %86
86: ; preds = %85
%87 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i8 0, i8* %87
%88 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%89 = call i32 @str_to_int(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 16, i32* %2, i8* %88, i32 512)
br label %90
90: ; preds = %86
%91 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%92 = load i8, i8* %91
%93 = sext i8 %92 to i32
store i32 %93, i32* %8
%94 = load i32, i32* %8
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %90
%97 = load i32, i32* @stderr
%98 = call i32 @fprintf(i32 %97, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%99 = load i32, i32* %8
store i32 %99, i32* %1
br label %161
100: ; preds = %90
br label %101
101: ; preds = %100
br label %102
102: ; preds = %101
%103 = load i32, i32* %2
%104 = icmp ne i32 %103, 15
br i1 %104, label %105, label %108
105: ; preds = %102
%106 = load i32, i32* @stderr
%107 = call i32 @fprintf(i32 %106, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %161
108: ; preds = %102
br label %109
109: ; preds = %108
%110 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i8 0, i8* %110
%111 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%112 = call i32 @str_to_int(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 10, i32* %2, i8* %111, i32 512)
br label %113
113: ; preds = %109
%114 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%115 = load i8, i8* %114
%116 = sext i8 %115 to i32
store i32 %116, i32* %9
%117 = load i32, i32* %9
%118 = icmp eq i32 %117, 0
br i1 %118, label %119, label %122
119: ; preds = %113
%120 = load i32, i32* @stderr
%121 = call i32 @fprintf(i32 %120, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 48, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %161
122: ; preds = %113
br label %123
123: ; preds = %122
%124 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i8 0, i8* %124
%125 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%126 = call i32 @str_to_int(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i32 10, i32* %2, i8* %125, i32 512)
br label %127
127: ; preds = %123
%128 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%129 = load i8, i8* %128
%130 = sext i8 %129 to i32
store i32 %130, i32* %10
%131 = load i32, i32* %10
%132 = icmp ne i32 %131, 0
br i1 %132, label %133, label %137
133: ; preds = %127
%134 = load i32, i32* @stderr
%135 = call i32 @fprintf(i32 %134, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 52, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%136 = load i32, i32* %10
store i32 %136, i32* %1
br label %161
137: ; preds = %127
br label %138
138: ; preds = %137
br label %139
139: ; preds = %138
%140 = load i32, i32* %2
%141 = icmp ne i32 %140, 2147483647
br i1 %141, label %142, label %145
142: ; preds = %139
%143 = load i32, i32* @stderr
%144 = call i32 @fprintf(i32 %143, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %161
145: ; preds = %139
br label %146
146: ; preds = %145
%147 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
store i8 0, i8* %147
%148 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%149 = call i32 @str_to_int(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 10, i32* %2, i8* %148, i32 512)
br label %150
150: ; preds = %146
%151 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%152 = load i8, i8* %151
%153 = sext i8 %152 to i32
store i32 %153, i32* %11
%154 = load i32, i32* %11
%155 = icmp eq i32 %154, 0
br i1 %155, label %156, label %159
156: ; preds = %150
%157 = load i32, i32* @stderr
%158 = call i32 @fprintf(i32 %157, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 57, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %161
159: ; preds = %150
br label %160
160: ; preds = %159
store i32 0, i32* %1
br label %161
161: ; preds = %160, %156, %142, %133, %119, %105, %96, %82, %68, %54, %45, %31, %22
%162 = load i32, i32* %1
ret i32 %162
}

LLVM IR (-O2):
@.str = [4 x i8] c"123\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"failed on line %d: %s\0A\00"
@.str.2 = [7 x i8] c"err[0]\00"
@.str.3 = [2 x i8] c"i\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [4 x i8] c"10b\00"
@.str.7 = [2 x i8] c"f\00"
@.str.8 = [11 x i8] c"8589934592\00"
@.str.9 = [11 x i8] c"2147483647\00"
@.str.10 = [5 x i8] c"blah\00"
define i32 @test_str_to_int() {
%1 = alloca i32
%2 = alloca [512 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = call i32 @str_to_int(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 10, i32* %1, i8* %4, i32 512)
%6 = load i8, i8* %4
%7 = icmp eq i8 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = sext i8 %6 to i32
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %88
12: ; preds = %0
%13 = load i32, i32* %1
%14 = icmp eq i32 %13, 123
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %88
18: ; preds = %12
store i8 0, i8* %4
%19 = call i32 @str_to_int(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 10, i32* %1, i8* %4, i32 512)
%20 = load i8, i8* %4
%21 = icmp eq i8 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = sext i8 %20 to i32
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %88
26: ; preds = %18
%27 = load i32, i32* %1
%28 = icmp eq i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %88
32: ; preds = %26
store i8 0, i8* %4
%33 = call i32 @str_to_int(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 10, i32* %1, i8* %4, i32 512)
%34 = load i8, i8* %4
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 35, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %88
39: ; preds = %32
store i8 0, i8* %4
%40 = call i32 @str_to_int(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i32 10, i32* %1, i8* %4, i32 512)
%41 = load i8, i8* %4
%42 = icmp eq i8 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %88
46: ; preds = %39
store i8 0, i8* %4
%47 = call i32 @str_to_int(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 16, i32* %1, i8* %4, i32 512)
%48 = load i8, i8* %4
%49 = icmp eq i8 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %46
%51 = sext i8 %48 to i32
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 43, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %88
54: ; preds = %46
%55 = load i32, i32* %1
%56 = icmp eq i32 %55, 15
br i1 %56, label %60, label %57
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %88
60: ; preds = %54
store i8 0, i8* %4
%61 = call i32 @str_to_int(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i32 10, i32* %1, i8* %4, i32 512)
%62 = load i8, i8* %4
%63 = icmp eq i8 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %60
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 48, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %88
67: ; preds = %60
store i8 0, i8* %4
%68 = call i32 @str_to_int(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0), i32 10, i32* %1, i8* %4, i32 512)
%69 = load i8, i8* %4
%70 = icmp eq i8 %69, 0
br i1 %70, label %75, label %71
71: ; preds = %67
%72 = sext i8 %69 to i32
%73 = load i32, i32* @stderr
%74 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 52, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %88
75: ; preds = %67
%76 = load i32, i32* %1
%77 = icmp eq i32 %76, 2147483647
br i1 %77, label %81, label %78
78: ; preds = %75
%79 = load i32, i32* @stderr
%80 = call i32 @fprintf(i32 %79, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %88
81: ; preds = %75
store i8 0, i8* %4
%82 = call i32 @str_to_int(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 10, i32* %1, i8* %4, i32 512)
%83 = load i8, i8* %4
%84 = icmp eq i8 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %81
%86 = load i32, i32* @stderr
%87 = call i32 @fprintf(i32 %86, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 57, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %88
88: ; preds = %85, %81, %71, %64, %50, %43, %36, %22, %8, %78, %57, %29, %15
%89 = phi i32 [ 1, %15 ], [ 1, %29 ], [ 1, %57 ], [ 1, %78 ], [ %72, %71 ], [ %51, %50 ], [ %23, %22 ], [ %9, %8 ], [ -1, %36 ], [ -1, %43 ], [ -1, %64 ], [ 0, %81 ], [ -1, %85 ]
ret i32 %89
}