int str_to_int(const char *str) {
  char *ptr;
  int ret_code;
  if (str[0] == '\0')
    fatal2("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/raven-au/ovlfs/refs/heads/master/tools/"
           "truncate.c",
           __FUNCTION__, 129, "invalid number: value is empty");
  ret_code = strtol(str, &ptr, 0);
  if (ptr[0] != '\0')
    fatal2("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/raven-au/ovlfs/refs/heads/master/tools/"
           "truncate.c",
           __FUNCTION__, 134, "invalid number, '%s'", str);
  return ret_code;
}


x86 assembly (clang, -O0):
<str_to_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    115d <str_to_int+0x3d>
lea    0xebd(%rip),%rdi
lea    0xf42(%rip),%rsi
mov    $0x81,%edx
lea    0xf41(%rip),%rcx
mov    $0x0,%al
call   1030 <fatal2@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a4 <str_to_int+0x84>
mov    -0x8(%rbp),%r8
lea    0xe76(%rip),%rdi
lea    0xefb(%rip),%rsi
mov    $0x86,%edx
lea    0xf19(%rip),%rcx
mov    $0x0,%al
call   1030 <fatal2@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_int>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
jne    114d <str_to_int+0x2d>
lea    0xecd(%rip),%rdi
lea    0xf52(%rip),%rsi
lea    0xf56(%rip),%rcx
mov    $0x81,%edx
xor    %eax,%eax
call   1030 <fatal2@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%r14
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     118a <str_to_int+0x6a>
lea    0xe93(%rip),%rdi
lea    0xf18(%rip),%rsi
lea    0xf3b(%rip),%rcx
mov    $0x86,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1030 <fatal2@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/raven-au/ovlfs/refs/heads/master/tools/truncate.c\00"
@__FUNCTION__.str_to_int = [11 x i8] c"str_to_int\00"
@.str.1 = [31 x i8] c"invalid number: value is empty\00"
@.str.2 = [21 x i8] c"invalid number, '%s'\00"
define i32 @str_to_int(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (i8*, i8*, i32, i8*, ...) bitcast (i32 (...)* @fatal2 to i32 (i8*, i8*, i32, i8*, ...)*)(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__FUNCTION__.str_to_int, i64 0, i64 0), i32 129, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = load i8*, i8** %2
%14 = call i64 @strtol(i8* %13, i8** %3, i32 0)
%15 = trunc i64 %14 to i32
store i32 %15, i32* %4
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i8*, i8** %2
%23 = call i32 (i8*, i8*, i32, i8*, i8*, ...) bitcast (i32 (...)* @fatal2 to i32 (i8*, i8*, i32, i8*, i8*, ...)*)(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__FUNCTION__.str_to_int, i64 0, i64 0), i32 134, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %12
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@.str = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/raven-au/ovlfs/refs/heads/master/tools/truncate.c\00"
@__FUNCTION__.str_to_int = [11 x i8] c"str_to_int\00"
@.str.1 = [31 x i8] c"invalid number: value is empty\00"
@.str.2 = [21 x i8] c"invalid number, '%s'\00"
define i32 @str_to_int(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i8*, i8*, i32, i8*, ...) bitcast (i32 (...)* @fatal2 to i32 (i8*, i8*, i32, i8*, ...)*)(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__FUNCTION__.str_to_int, i64 0, i64 0), i32 129, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = call i64 @strtol(i8* %0, i8** %2, i32 0)
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = tail call i32 (i8*, i8*, i32, i8*, i8*, ...) bitcast (i32 (...)* @fatal2 to i32 (i8*, i8*, i32, i8*, i8*, ...)*)(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__FUNCTION__.str_to_int, i64 0, i64 0), i32 134, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %13, %8
%16 = trunc i64 %9 to i32
ret i32 %16
}