char *strchr(const char *string, int c_) {
  char c = c_;
  if (string != ((void *)0)) {
  } else {
    debug_panic("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/Coding-Headache/CNOS/refs/"
                "heads/master/OS_Dev/pintos/lib/string.c",
                117, __func__, "assertion `%s' failed.", "string != NULL");
  };
  for (;;)
    if (*string == c)
      return (char *)string;
    else if (*string == '\0')
      return ((void *)0);
    else
      string++;
}


x86 assembly (clang, -O0):
<strchr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %al,-0x15(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1135 <strchr+0x25>
jmp    115d <strchr+0x4d>
lea    0xec4(%rip),%rdi
mov    $0x75,%esi
lea    0xf54(%rip),%rdx
lea    0xf54(%rip),%rcx
lea    0xf64(%rip),%r8
mov    $0x0,%al
call   1030 <debug_panic@plt>
jmp    1162 <strchr+0x52>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x15(%rbp),%ecx
cmp    %ecx,%eax
jne    1182 <strchr+0x72>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11b5 <strchr+0xa5>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    119f <strchr+0x8f>
movq   $0x0,-0x8(%rbp)
jmp    11b5 <strchr+0xa5>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b0 <strchr+0xa0>
jmp    1162 <strchr+0x52>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strchr>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
test   %rdi,%rdi
jne    1145 <strchr+0x35>
lea    0xedc(%rip),%rdi
lea    0xf71(%rip),%rdx
lea    0xf71(%rip),%rcx
lea    0xf81(%rip),%r8
mov    $0x75,%esi
xor    %eax,%eax
call   1030 <debug_panic@plt>
movsbl %bpl,%eax
movsbl (%rbx),%ecx
cmp    %ecx,%eax
je     1164 <strchr+0x54>
test   %cl,%cl
je     1162 <strchr+0x52>
movsbl 0x1(%rbx),%ecx
add    $0x1,%rbx
cmp    %ecx,%eax
jne    1150 <strchr+0x40>
jmp    1164 <strchr+0x54>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Coding-Headache/CNOS/refs/heads/master/OS_Dev/pintos/lib/string.c\00"
@__func__.strchr = [7 x i8] c"strchr\00"
@.str.1 = [23 x i8] c"assertion `%s' failed.\00"
@.str.2 = [15 x i8] c"string != NULL\00"
define i8* @strchr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = trunc i32 %7 to i8
store i8 %8, i8* %6
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
br label %14
12: ; preds = %2
%13 = call i32 (i8*, i32, i8*, i8*, i8*, ...) bitcast (i32 (...)* @debug_panic to i32 (i8*, i32, i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str, i64 0, i64 0), i32 117, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__func__.strchr, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %11
br label %15
15: ; preds = %34, %14
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = load i8, i8* %6
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %18, %20
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = load i8*, i8** %4
store i8* %23, i8** %3
br label %35
24: ; preds = %15
%25 = load i8*, i8** %4
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %24
store i8* null, i8** %3
br label %35
30: ; preds = %24
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
br label %33
33: ; preds = %30
br label %34
34: ; preds = %33
br label %15
35: ; preds = %29, %22
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
@.str = [156 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Coding-Headache/CNOS/refs/heads/master/OS_Dev/pintos/lib/string.c\00"
@__func__.strchr = [7 x i8] c"strchr\00"
@.str.1 = [23 x i8] c"assertion `%s' failed.\00"
@.str.2 = [15 x i8] c"string != NULL\00"
define i8* @strchr(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) bitcast (i32 (...)* @debug_panic to i32 (i8*, i32, i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([156 x i8], [156 x i8]* @.str, i64 0, i64 0), i32 117, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @__func__.strchr, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
br label %6
6: ; preds = %2, %4
%7 = shl i32 %1, 24
%8 = ashr exact i32 %7, 24
%9 = load i8, i8* %0
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %8, %10
br i1 %11, label %21, label %12
12: ; preds = %6, %16
%13 = phi i8 [ %18, %16 ], [ %9, %6 ]
%14 = phi i8* [ %17, %16 ], [ %0, %6 ]
%15 = icmp eq i8 %13, 0
br i1 %15, label %21, label %16
16: ; preds = %12
%17 = getelementptr inbounds i8, i8* %14, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %8, %19
br i1 %20, label %21, label %12
21: ; preds = %16, %12, %6
%22 = phi i8* [ %0, %6 ], [ null, %12 ], [ %17, %16 ]
ret i8* %22
}