#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__ atof(char *);
int opt_isvalidnumber(char *);
int /*<<< orphan*/ opt_warning(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, long);
long opt_atoi(char *s) {
  int valid;
  long x;
  x = (long)atof(s);
  valid = opt_isvalidnumber(s);
  if (!valid || (valid & 0x2)) {
    do {
      char gstr[1024];
      sprintf(gstr, "String [%s] is not a valid integer, will use [%ld]", s, x);
      opt_warning(gstr);
    } while (0);
  }
  return x;
}


x86 assembly (clang, -O0):
<opt_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <atof@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <opt_isvalidnumber@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1181 <opt_atoi+0x41>
mov    -0xc(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     11b2 <opt_atoi+0x72>
jmp    1186 <opt_atoi+0x46>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe64(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <opt_warning@plt>
jmp    11b2 <opt_atoi+0x72>
mov    -0x18(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_atoi>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rbx
call   1030 <atof@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <opt_isvalidnumber@plt>
test   %eax,%eax
je     1168 <opt_atoi+0x28>
and    $0x2,%eax
je     1188 <opt_atoi+0x48>
lea    0xe91(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1040 <opt_warning@plt>
mov    %r14,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [51 x i8] c"String [%s] is not a valid integer, will use [%ld]\00"
define i64 @opt_atoi(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca [1024 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i64 @atof(i8* %6)
store i64 %7, i64* %4
%8 = load i8*, i8** %2
%9 = call i32 @opt_isvalidnumber(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* %3
%14 = and i32 %13, 2
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %12, %1
br label %17
17: ; preds = %16
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%19 = load i8*, i8** %2
%20 = load i64, i64* %4
%21 = call i32 @sprintf(i8* %18, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %19, i64 %20)
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = call i32 @opt_warning(i8* %22)
br label %24
24: ; preds = %17
br label %25
25: ; preds = %24, %12
%26 = load i64, i64* %4
ret i64 %26
}

LLVM IR (-O2):
@.str = [51 x i8] c"String [%s] is not a valid integer, will use [%ld]\00"
define i64 @opt_atoi(i8* %0) {
%2 = alloca [1024 x i8]
%3 = tail call i64 @atof(i8* %0)
%4 = tail call i32 @opt_isvalidnumber(i8* %0)
%5 = icmp ne i32 %4, 0
%6 = and i32 %4, 2
%7 = icmp eq i32 %6, 0
%8 = and i1 %5, %7
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%11 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %3)
%12 = call i32 @opt_warning(i8* %10)
br label %13
13: ; preds = %1, %9
ret i64 %3
}