int strlen(const char *str) {
  const char *c = str;
  int count = 0;
  if (!(str != 0)) {
    printf("!!!Failed assertion: `%s' in %s: %d in %s \n\n", "str != NULL",
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/kylios/kylux/refs/heads/master/src/lib/"
           "string.c",
           68, __func__);
    debug_backtrace();
    while (1)
      ;
  };
  while (*c++ != '\0') {
    count++;
  }
  return count;
}


x86 assembly (clang, -O0):
<strlen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117a <strlen+0x5a>
lea    0xeb3(%rip),%rdi
lea    0xed9(%rip),%rsi
lea    0xede(%rip),%rdx
mov    $0x44,%ecx
lea    0xf5c(%rip),%r8
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <debug_backtrace@plt>
jmp    1175 <strlen+0x55>
jmp    117f <strlen+0x5f>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a8 <strlen+0x88>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117f <strlen+0x5f>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strlen>:
push   %rax
test   %rdi,%rdi
je     113d <strlen+0x1d>
cmpb   $0x0,(%rdi)
je     1172 <strlen+0x52>
xor    %eax,%eax
nopl   (%rax)
cmpb   $0x0,0x1(%rdi,%rax,1)
lea    0x1(%rax),%rax
jne    1130 <strlen+0x10>
pop    %rcx
ret
lea    0xebc(%rip),%rdi
lea    0xee2(%rip),%rsi
lea    0xee7(%rip),%rdx
lea    0xf6a(%rip),%r8
mov    $0x44,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <debug_backtrace@plt>
nopl   0x0(%rax)
jmp    1170 <strlen+0x50>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [45 x i8] c"!!!Failed assertion: `%s' in %s: %d in %s \0A\0A\00"
@.str.1 = [12 x i8] c"str != NULL\00"
@.str.2 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kylios/kylux/refs/heads/master/src/lib/string.c\00"
@__func__.strlen = [7 x i8] c"strlen\00"
define i32 @strlen(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
store i32 0, i32* %4
%6 = load i8*, i8** %2
%7 = icmp ne i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 68, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__func__.strlen, i64 0, i64 0))
%10 = call i32 (...) @debug_backtrace()
br label %11
11: ; preds = %8, %11
br label %11
12: ; preds = %1
br label %13
13: ; preds = %19, %12
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %3
%16 = load i8, i8* %14
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %13
22: ; preds = %13
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
@.str = [45 x i8] c"!!!Failed assertion: `%s' in %s: %d in %s \0A\0A\00"
@.str.1 = [12 x i8] c"str != NULL\00"
@.str.2 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kylios/kylux/refs/heads/master/src/lib/string.c\00"
@__func__.strlen = [7 x i8] c"strlen\00"
define i32 @strlen(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %6, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %17, label %10
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.2, i64 0, i64 0), i32 68, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__func__.strlen, i64 0, i64 0))
%8 = tail call i32 (...) @debug_backtrace()
br label %9
9: ; preds = %9, %6
br label %9
10: ; preds = %3, %10
%11 = phi i32 [ %14, %10 ], [ 0, %3 ]
%12 = phi i8* [ %13, %10 ], [ %0, %3 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = add nuw nsw i32 %11, 1
%15 = load i8, i8* %13
%16 = icmp eq i8 %15, 0
br i1 %16, label %17, label %10
17: ; preds = %10, %3
%18 = phi i32 [ 0, %3 ], [ %14, %10 ]
ret i32 %18
}