#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 */
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int strlen(char *);
int str2int(char str[], int max_size, int *success) {
  int num;
  int i;
  for (i = 0; i < strlen(str); i++) {
    if (str[i] == '\r') {
      str[i] = '\0';
    }
  }
  for (i = 0; str[i] != '\0'; i++) {
    if (isdigit(str[i])) {
    } else {
      printf("\nFail\n");
      *success = 0;
      return 0;
    }
  }
  printf("\nSuccess\n");
  *success = 1;
  sscanf(str, "%d", &num);
  return num;
}


x86 assembly (clang, -O0):
<str2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    11aa <str2int+0x6a>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    1197 <str2int+0x57>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    119c <str2int+0x5c>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    115a <str2int+0x1a>
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     121b <str2int+0xdb>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e6 <str2int+0xa6>
jmp    1208 <str2int+0xc8>
lea    0xe13(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    124b <str2int+0x10b>
jmp    120d <str2int+0xcd>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11b1 <str2int+0x71>
lea    0xde5(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rdi
lea    0xdd5(%rip),%rsi
lea    -0x24(%rbp),%rdx
call   1060 <sscanf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2int>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rdi,%r15
call   1050 <strlen@plt>
test   %eax,%eax
jle    1181 <str2int+0x41>
xor    %ebx,%ebx
jmp    1173 <str2int+0x33>
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1181 <str2int+0x41>
cmpb   $0xd,(%r15,%rbx,1)
jne    1160 <str2int+0x20>
movb   $0x0,(%r15,%rbx,1)
jmp    1160 <str2int+0x20>
mov    (%r15),%al
test   %al,%al
je     11a8 <str2int+0x68>
lea    0x1(%r15),%rbx
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11d5 <str2int+0x95>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1190 <str2int+0x50>
lea    0xe54(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,(%r14)
lea    0xe3e(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %r15,%rdi
call   1060 <sscanf@plt>
mov    0xc(%rsp),%eax
jmp    11ea <str2int+0xaa>
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,(%r14)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"\0AFail\0A\00"
@.str.1 = [10 x i8] c"\0ASuccess\0A\00"
@.str.2 = [3 x i8] c"%d\00"
define i32 @str2int(i8* %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32* %2, i32** %7
store i32 0, i32* %9
br label %10
10: ; preds = %29, %3
%11 = load i32, i32* %9
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %32
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 13
br i1 %22, label %23, label %28
23: ; preds = %15
%24 = load i8*, i8** %5
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 0, i8* %27
br label %28
28: ; preds = %23, %15
br label %29
29: ; preds = %28
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
br label %10
32: ; preds = %10
store i32 0, i32* %9
br label %33
33: ; preds = %54, %32
%34 = load i8*, i8** %5
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %57
41: ; preds = %33
%42 = load i8*, i8** %5
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = call i64 @isdigit(i8 signext %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %41
br label %53
50: ; preds = %41
%51 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%52 = load i32*, i32** %7
store i32 0, i32* %52
store i32 0, i32* %4
br label %63
53: ; preds = %49
br label %54
54: ; preds = %53
%55 = load i32, i32* %9
%56 = add nsw i32 %55, 1
store i32 %56, i32* %9
br label %33
57: ; preds = %33
%58 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%59 = load i32*, i32** %7
store i32 1, i32* %59
%60 = load i8*, i8** %5
%61 = call i32 @sscanf(i8* %60, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %8)
%62 = load i32, i32* %8
store i32 %62, i32* %4
br label %63
63: ; preds = %57, %50
%64 = load i32, i32* %4
ret i32 %64
}

LLVM IR (-O2):
@.str.2 = [3 x i8] c"%d\00"
@str = [9 x i8] c"\0ASuccess\00"
@str.3 = [6 x i8] c"\0AFail\00"
define i32 @str2int(i8* %0, i32 %1, i32* nocapture writeonly %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %17, %3
%9 = load i8, i8* %0
%10 = icmp eq i8 %9, 0
br i1 %10, label %34, label %26
11: ; preds = %3, %17
%12 = phi i64 [ %18, %17 ], [ 0, %3 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 13
br i1 %15, label %16, label %17
16: ; preds = %11
store i8 0, i8* %13
br label %17
17: ; preds = %11, %16
%18 = add nuw nsw i64 %12, 1
%19 = tail call i32 @strlen(i8* %0)
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %11, label %8
22: ; preds = %26
%23 = getelementptr inbounds i8, i8* %0, i64 %31
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %34, label %26
26: ; preds = %8, %22
%27 = phi i64 [ %31, %22 ], [ 0, %8 ]
%28 = phi i8 [ %24, %22 ], [ %9, %8 ]
%29 = tail call i64 @isdigit(i8 signext %28)
%30 = icmp eq i64 %29, 0
%31 = add nuw i64 %27, 1
br i1 %30, label %32, label %22
32: ; preds = %26
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %38
34: ; preds = %22, %8
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
store i32 1, i32* %2
%36 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%37 = load i32, i32* %4
br label %38
38: ; preds = %34, %32
%39 = phi i32 [ 0, %32 ], [ %37, %34 ]
ret i32 %39
}