#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 strtol(char const *, char **, int);
int arg_to_num(const char *arg, int *success) {
  char *endptr;
  int out = strtol(arg, &endptr, 10);
  if ((*arg) == '\0' || (*endptr) != '\0') {
    if (success) {
      (*success) = 0;
    }
    out = -1;
  } else {
    if (success) {
      (*success) = 1;
    }
  }
  return out;
}


x86 assembly (clang, -O0):
<arg_to_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1155 <arg_to_num+0x45>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1176 <arg_to_num+0x66>
cmpq   $0x0,-0x10(%rbp)
je     116a <arg_to_num+0x5a>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movl   $0xffffffff,-0x1c(%rbp)
jmp    1190 <arg_to_num+0x80>
cmpq   $0x0,-0x10(%rbp)
je     118b <arg_to_num+0x7b>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    1190 <arg_to_num+0x80>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arg_to_num>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
cmpb   $0x0,(%rbx)
je     1135 <arg_to_num+0x25>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
je     114c <arg_to_num+0x3c>
xor    %ecx,%ecx
mov    $0xffffffff,%eax
test   %r14,%r14
je     1144 <arg_to_num+0x34>
mov    %ecx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0x1,%ecx
test   %r14,%r14
jne    1141 <arg_to_num+0x31>
jmp    1144 <arg_to_num+0x34>

LLVM IR (-O0):
define i32 @arg_to_num(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%7 = load i8*, i8** %3
%8 = call i32 @strtol(i8* %7, i8** %5, i32 10)
store i32 %8, i32* %6
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %13, %2
%19 = load i32*, i32** %4
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = load i32*, i32** %4
store i32 0, i32* %22
br label %23
23: ; preds = %21, %18
store i32 -1, i32* %6
br label %30
24: ; preds = %13
%25 = load i32*, i32** %4
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = load i32*, i32** %4
store i32 1, i32* %28
br label %29
29: ; preds = %27, %24
br label %30
30: ; preds = %29, %23
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
define i32 @arg_to_num(i8* %0, i32* writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8, %2
%13 = icmp eq i32* %1, null
br i1 %13, label %19, label %16
14: ; preds = %8
%15 = icmp eq i32* %1, null
br i1 %15, label %19, label %16
16: ; preds = %14, %12
%17 = phi i32 [ 0, %12 ], [ 1, %14 ]
%18 = phi i32 [ -1, %12 ], [ %5, %14 ]
store i32 %17, i32* %1
br label %19
19: ; preds = %16, %12, %14
%20 = phi i32 [ %5, %14 ], [ -1, %12 ], [ %18, %16 ]
ret i32 %20
}