#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 *);
char *calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int strlen(char *);
int opt_atoi(char *str, char opt, char *env, int from_option,
             int default_value) {
  char *source;
  if (!str)
    return default_value;
  if (!(*str >= '0' && *str <= '9')) {
    if (from_option) {
      source = calloc(15, sizeof(char));
      sprintf(source, "argument to -%c", opt);
    } else {
      source = calloc(22 + strlen(env), sizeof(char));
      sprintf(source, "environment variable %s", env);
    }
    fprintf(stderr, "Warning: %s [%s] is not a numeric value, set to 0\n",
            source, str);
    free(source);
    return 0;
  }
  return atoi(str);
}


x86 assembly (clang, -O0):
<opt_atoi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <opt_atoi+0x33>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    125b <opt_atoi+0xfb>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     11b3 <opt_atoi+0x53>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jle    124f <opt_atoi+0xef>
cmpl   $0x0,-0x24(%rbp)
je     11eb <opt_atoi+0x8b>
mov    $0xf,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
movsbl -0x11(%rbp),%edx
lea    0xe21(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
jmp    121d <opt_atoi+0xbd>
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x16,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdf3(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    125b <opt_atoi+0xfb>
mov    -0x10(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_atoi>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1211 <opt_atoi+0xb1>
mov    %rdi,%rbx
mov    (%rdi),%al
add    $0xd0,%al
cmp    $0xa,%al
jae    118d <opt_atoi+0x2d>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <atoi@plt>
test   %ecx,%ecx
je     11bc <opt_atoi+0x5c>
mov    %esi,%ebp
mov    $0xf,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
movsbl %bpl,%edx
lea    0xe50(%rip),%rsi
mov    %rax,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
jmp    11eb <opt_atoi+0x8b>
mov    %rdx,%r15
mov    %rdx,%rdi
call   1040 <strlen@plt>
lea    0x16(%rax),%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
lea    0xe32(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1060 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r8d,%r8d
mov    %r8d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"argument to -%c\00"
@.str.1 = [24 x i8] c"environment variable %s\00"
@stderr = global i32 0
@.str.2 = [51 x i8] c"Warning: %s [%s] is not a numeric value, set to 0\0A\00"
define i32 @opt_atoi(i8* %0, i8 signext %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %7
store i8 %1, i8* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %5
%16 = load i32, i32* %11
store i32 %16, i32* %6
br label %54
17: ; preds = %5
%18 = load i8*, i8** %7
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp sge i32 %20, 48
br i1 %21, label %22, label %27
22: ; preds = %17
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp sle i32 %25, 57
br i1 %26, label %51, label %27
27: ; preds = %22, %17
%28 = load i32, i32* %10
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = call i8* @calloc(i32 15, i32 1)
store i8* %31, i8** %12
%32 = load i8*, i8** %12
%33 = load i8, i8* %8
%34 = sext i8 %33 to i32
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %32, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %34)
br label %44
36: ; preds = %27
%37 = load i8*, i8** %9
%38 = call i32 @strlen(i8* %37)
%39 = add nsw i32 22, %38
%40 = call i8* @calloc(i32 %39, i32 1)
store i8* %40, i8** %12
%41 = load i8*, i8** %12
%42 = load i8*, i8** %9
%43 = call i32 (i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %36, %30
%45 = load i32, i32* @stderr
%46 = load i8*, i8** %12
%47 = load i8*, i8** %7
%48 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %46, i8* %47)
%49 = load i8*, i8** %12
%50 = call i32 @free(i8* %49)
store i32 0, i32* %6
br label %54
51: ; preds = %22
%52 = load i8*, i8** %7
%53 = call i32 @atoi(i8* %52)
store i32 %53, i32* %6
br label %54
54: ; preds = %51, %44, %15
%55 = load i32, i32* %6
ret i32 %55
}

LLVM IR (-O2):
@.str = [16 x i8] c"argument to -%c\00"
@.str.1 = [24 x i8] c"environment variable %s\00"
@stderr = global i32 0
@.str.2 = [51 x i8] c"Warning: %s [%s] is not a numeric value, set to 0\0A\00"
define i32 @opt_atoi(i8* %0, i8 signext %1, i8* %2, i32 %3, i32 %4) {
%6 = icmp eq i8* %0, null
br i1 %6, label %29, label %7
7: ; preds = %5
%8 = load i8, i8* %0
%9 = add i8 %8, -48
%10 = icmp ult i8 %9, 10
br i1 %10, label %27, label %11
11: ; preds = %7
%12 = icmp eq i32 %3, 0
br i1 %12, label %17, label %13
13: ; preds = %11
%14 = tail call dereferenceable_or_null(15) i8* @calloc(i32 15, i32 1)
%15 = sext i8 %1 to i32
%16 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %15)
br label %22
17: ; preds = %11
%18 = tail call i32 @strlen(i8* %2)
%19 = add nsw i32 %18, 22
%20 = tail call i8* @calloc(i32 %19, i32 1)
%21 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %22
22: ; preds = %17, %13
%23 = phi i8* [ %14, %13 ], [ %20, %17 ]
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %0)
%26 = tail call i32 @free(i8* %23)
br label %29
27: ; preds = %7
%28 = tail call i32 @atoi(i8* %0)
br label %29
29: ; preds = %5, %27, %22
%30 = phi i32 [ %28, %27 ], [ 0, %22 ], [ %4, %5 ]
ret i32 %30
}