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


x86 assembly (clang, -O0):
<opt_atou>:
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     1190 <opt_atou+0x50>
mov    -0xc(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    1190 <opt_atou+0x50>
mov    -0xc(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11c1 <opt_atou+0x81>
jmp    1195 <opt_atou+0x55>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe55(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x420(%rbp),%rdi
call   1040 <opt_warning@plt>
jmp    11c1 <opt_atou+0x81>
mov    -0x18(%rbp),%rax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_atou>:
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_atou+0x28>
and    $0x6,%eax
je     1188 <opt_atou+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 = [60 x i8] c"String [%s] is not a valid positive integer, will use [%lu]\00"
define i64 @opt_atou(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 %20
12: ; preds = %1
%13 = load i32, i32* %3
%14 = and i32 %13, 2
%15 = icmp ne i32 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i32, i32* %3
%18 = and i32 %17, 4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %29
20: ; preds = %16, %12, %1
br label %21
21: ; preds = %20
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = load i8*, i8** %2
%24 = load i64, i64* %4
%25 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %23, i64 %24)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%27 = call i32 @opt_warning(i8* %26)
br label %28
28: ; preds = %21
br label %29
29: ; preds = %28, %16
%30 = load i64, i64* %4
ret i64 %30
}

LLVM IR (-O2):
@.str = [60 x i8] c"String [%s] is not a valid positive integer, will use [%lu]\00"
define i64 @opt_atou(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, 6
%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 ([60 x i8], [60 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
}