#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 /*<<< orphan*/ TEMP_LOG(int, char *, int, char *, ...);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ isspace(char const);
int strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
int ds18b20_verify_crc(const char *buf) {
  assert(buf != NULL);
  int len = strlen(buf);
  const char *crc = &(buf[len - 1]);
  if (*crc == '\n') {
    --crc;
  }
  while (isspace(*crc) == 0) {
    --crc;
  }
  ++crc;
  if (strncmp(crc, "YES", 3) == 0) {
    TEMP_LOG((5),
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/heads/"
             "master/temperature/source/ds18b20.c",
             51, "CRC verify success!\n");
    return (1);
  } else if (strncmp(crc, "NO", 2) == 0) {
    TEMP_LOG((2),
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/heads/"
             "master/temperature/source/ds18b20.c",
             54, "CRC verify failed!\n");
    return (0);
  } else {
    TEMP_LOG((2),
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/heads/"
             "master/temperature/source/ds18b20.c",
             57, "Unexpected CRC verify result (%s)!\n", crc);
    return (0);
  }
}


x86 assembly (clang, -O0):
<ds18b20_verify_crc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11aa <ds18b20_verify_crc+0x5a>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11af <ds18b20_verify_crc+0x5f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
jne    11d6 <ds18b20_verify_crc+0x86>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    11af <ds18b20_verify_crc+0x5f>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe13(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    122c <ds18b20_verify_crc+0xdc>
mov    $0x5,%edi
lea    0xdf7(%rip),%rsi
mov    $0x33,%edx
lea    0xe8c(%rip),%rcx
mov    $0x0,%al
call   1060 <TEMP_LOG@plt>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <ds18b20_verify_crc+0x150>
mov    -0x20(%rbp),%rdi
lea    0xe83(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1276 <ds18b20_verify_crc+0x126>
mov    $0x2,%edi
lea    0xdad(%rip),%rsi
mov    $0x36,%edx
lea    0xe5a(%rip),%rcx
mov    $0x0,%al
call   1060 <TEMP_LOG@plt>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <ds18b20_verify_crc+0x150>
mov    -0x20(%rbp),%r8
mov    $0x2,%edi
lea    0xd7e(%rip),%rsi
mov    $0x39,%edx
lea    0xe3f(%rip),%rcx
mov    $0x0,%al
call   1060 <TEMP_LOG@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds18b20_verify_crc>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
xor    %ecx,%ecx
cmpb   $0xa,-0x1(%rbx,%rax,1)
lea    -0x1(%rax),%rax
sete   %cl
sub    %rcx,%rax
add    %rax,%rbx
add    $0x2,%rbx
cs nopw 0x0(%rax,%rax,1)
movsbl -0x2(%rbx),%edi
call   1050 <isspace@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
je     1190 <ds18b20_verify_crc+0x40>
lea    0xe57(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11fa <ds18b20_verify_crc+0xaa>
lea    0xef8(%rip),%rsi
mov    %rbx,%rdi
mov    $0x2,%edx
call   1030 <strncmp@plt>
lea    0xe2e(%rip),%rsi
test   %rax,%rax
je     1220 <ds18b20_verify_crc+0xd0>
lea    0xeef(%rip),%rcx
xor    %ebp,%ebp
mov    $0x2,%edi
mov    $0x39,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <TEMP_LOG@plt>
jmp    123a <ds18b20_verify_crc+0xea>
lea    0xe03(%rip),%rsi
lea    0xe9d(%rip),%rcx
mov    $0x5,%edi
mov    $0x33,%edx
xor    %eax,%eax
call   1060 <TEMP_LOG@plt>
mov    $0x1,%ebp
jmp    123a <ds18b20_verify_crc+0xea>
lea    0xe96(%rip),%rcx
xor    %ebp,%ebp
mov    $0x2,%edi
mov    $0x36,%edx
xor    %eax,%eax
call   1060 <TEMP_LOG@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"YES\00"
@.str.1 = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/heads/master/temperature/source/ds18b20.c\00"
@.str.2 = [21 x i8] c"CRC verify success!\0A\00"
@.str.3 = [3 x i8] c"NO\00"
@.str.4 = [20 x i8] c"CRC verify failed!\0A\00"
@.str.5 = [36 x i8] c"Unexpected CRC verify result (%s)!\0A\00"
define i32 @ds18b20_verify_crc(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %4
%12 = load i8*, i8** %3
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %24
21: ; preds = %1
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i32 -1
store i8* %23, i8** %5
br label %24
24: ; preds = %21, %1
br label %25
25: ; preds = %30, %24
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = call i64 @isspace(i8 signext %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 -1
store i8* %32, i8** %5
br label %25
33: ; preds = %25
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
%36 = load i8*, i8** %5
%37 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 5, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %50
41: ; preds = %33
%42 = load i8*, i8** %5
%43 = call i64 @strncmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 54, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %2
br label %50
47: ; preds = %41
%48 = load i8*, i8** %5
%49 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 57, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %48)
store i32 0, i32* %2
br label %50
50: ; preds = %47, %45, %39
%51 = load i32, i32* %2
ret i32 %51
}

LLVM IR (-O2):
@.str = [4 x i8] c"YES\00"
@.str.1 = [161 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/cugfeng/Home_Automation/refs/heads/master/temperature/source/ds18b20.c\00"
@.str.2 = [21 x i8] c"CRC verify success!\0A\00"
@.str.3 = [3 x i8] c"NO\00"
@.str.4 = [20 x i8] c"CRC verify failed!\0A\00"
@.str.5 = [36 x i8] c"Unexpected CRC verify result (%s)!\0A\00"
define i32 @ds18b20_verify_crc(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 10
%11 = sext i1 %10 to i64
%12 = getelementptr i8, i8* %8, i64 %11
br label %13
13: ; preds = %13, %1
%14 = phi i8* [ %12, %1 ], [ %18, %13 ]
%15 = load i8, i8* %14
%16 = tail call i64 @isspace(i8 signext %15)
%17 = icmp eq i64 %16, 0
%18 = getelementptr inbounds i8, i8* %14, i64 -1
br i1 %17, label %13, label %19
19: ; preds = %13
%20 = getelementptr inbounds i8, i8* %14, i64 1
%21 = tail call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = tail call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 5, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %32
25: ; preds = %19
%26 = tail call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 2)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 54, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %32
30: ; preds = %25
%31 = tail call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str.1, i64 0, i64 0), i32 57, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i8* %20)
br label %32
32: ; preds = %30, %28, %23
%33 = phi i32 [ 1, %23 ], [ 0, %28 ], [ 0, %30 ]
ret i32 %33
}