#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*/);
int atoi(char const *);
int strlen(char const *);
int ds18b20_decode_temp(const char *buf) {
  assert(buf != NULL);
  int len = strlen(buf);
  const char *p_temp = &(buf[len - 1]);
  int i_temp = -1;
  int found = 0;
  if (*p_temp == '\n') {
    --p_temp;
  }
  --p_temp;
  while (p_temp >= buf) {
    if (p_temp[0] == 't' && p_temp[1] == '=') {
      p_temp += 2;
      found = 1;
      break;
    }
    --p_temp;
  }
  if (found == 1) {
    i_temp = atoi(p_temp);
    TEMP_LOG((3),
             "/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",
             86, "Temperature is %d\n", i_temp);
  } 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",
             88, "Cannot find temperature in buffer (%s)!\n", buf);
    i_temp = -1;
  }
  return i_temp;
}


x86 assembly (clang, -O0):
<ds18b20_decode_temp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11a8 <ds18b20_decode_temp+0x68>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jb     120c <ds18b20_decode_temp+0xcc>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x74,%eax
jne    11fb <ds18b20_decode_temp+0xbb>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x3d,%eax
jne    11fb <ds18b20_decode_temp+0xbb>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    120c <ds18b20_decode_temp+0xcc>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    11b4 <ds18b20_decode_temp+0x74>
cmpl   $0x1,-0x20(%rbp)
jne    124a <ds18b20_decode_temp+0x10a>
mov    -0x18(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%r8d
mov    $0x3,%edi
lea    0xdce(%rip),%rsi
mov    $0x56,%edx
lea    0xe63(%rip),%rcx
mov    $0x0,%al
call   1040 <TEMP_LOG@plt>
jmp    1274 <ds18b20_decode_temp+0x134>
mov    -0x8(%rbp),%r8
mov    $0x2,%edi
lea    0xda6(%rip),%rsi
mov    $0x58,%edx
lea    0xe4e(%rip),%rcx
mov    $0x0,%al
call   1040 <TEMP_LOG@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds18b20_decode_temp>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%rcx
xor    %edx,%edx
cmpb   $0xa,-0x1(%rax,%rbx,1)
sete   %dl
not    %rdx
lea    (%rdx,%rcx,1),%rdi
add    $0xffffffffffffffff,%rdi
jmp    1184 <ds18b20_decode_temp+0x44>
nopw   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rdi
cmp    %rbx,%rdi
jb     11c3 <ds18b20_decode_temp+0x83>
cmpb   $0x74,(%rdi)
jne    1180 <ds18b20_decode_temp+0x40>
cmpb   $0x3d,0x1(%rdi)
jne    1180 <ds18b20_decode_temp+0x40>
add    $0x2,%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
lea    0xe5a(%rip),%rsi
lea    0xef4(%rip),%rcx
mov    $0x3,%edi
mov    $0x56,%edx
mov    %eax,%r8d
xor    %eax,%eax
call   1040 <TEMP_LOG@plt>
jmp    11ea <ds18b20_decode_temp+0xaa>
lea    0xe36(%rip),%rsi
lea    0xee3(%rip),%rcx
mov    $0x2,%edi
mov    $0x58,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1040 <TEMP_LOG@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [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.1 = [19 x i8] c"Temperature is %d\0A\00"
@.str.2 = [41 x i8] c"Cannot find temperature in buffer (%s)!\0A\00"
define i32 @ds18b20_decode_temp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %3
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8* %17, i8** %4
store i32 -1, i32* %5
store i32 0, i32* %6
%18 = load i8*, i8** %4
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %25
22: ; preds = %1
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %4
br label %25
25: ; preds = %22, %1
%26 = load i8*, i8** %4
%27 = getelementptr inbounds i8, i8* %26, i32 -1
store i8* %27, i8** %4
br label %28
28: ; preds = %47, %25
%29 = load i8*, i8** %4
%30 = load i8*, i8** %2
%31 = icmp uge i8* %29, %30
br i1 %31, label %32, label %50
32: ; preds = %28
%33 = load i8*, i8** %4
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 116
br i1 %37, label %38, label %47
38: ; preds = %32
%39 = load i8*, i8** %4
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 61
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i64 2
store i8* %46, i8** %4
store i32 1, i32* %6
br label %50
47: ; preds = %38, %32
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i32 -1
store i8* %49, i8** %4
br label %28
50: ; preds = %44, %28
%51 = load i32, i32* %6
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %58
53: ; preds = %50
%54 = load i8*, i8** %4
%55 = call i32 @atoi(i8* %54)
store i32 %55, i32* %5
%56 = load i32, i32* %5
%57 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 3, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str, i64 0, i64 0), i32 86, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %56)
br label %61
58: ; preds = %50
%59 = load i8*, i8** %2
%60 = call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str, i64 0, i64 0), i32 88, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %59)
store i32 -1, i32* %5
br label %61
61: ; preds = %58, %53
%62 = load i32, i32* %5
ret i32 %62
}

LLVM IR (-O2):
@.str = [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.1 = [19 x i8] c"Temperature is %d\0A\00"
@.str.2 = [41 x i8] c"Cannot find temperature in buffer (%s)!\0A\00"
define i32 @ds18b20_decode_temp(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
%13 = getelementptr inbounds i8, i8* %12, i64 -1
%14 = icmp ult i8* %13, %0
br i1 %14, label %30, label %15
15: ; preds = %1, %23
%16 = phi i8* [ %24, %23 ], [ %13, %1 ]
%17 = phi i8* [ %16, %23 ], [ %12, %1 ]
%18 = load i8, i8* %16
%19 = icmp eq i8 %18, 116
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8, i8* %17
%22 = icmp eq i8 %21, 61
br i1 %22, label %26, label %23
23: ; preds = %20, %15
%24 = getelementptr inbounds i8, i8* %16, i64 -1
%25 = icmp ult i8* %24, %0
br i1 %25, label %30, label %15
26: ; preds = %20
%27 = getelementptr inbounds i8, i8* %17, i64 1
%28 = tail call i32 @atoi(i8* %27)
%29 = tail call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 3, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str, i64 0, i64 0), i32 86, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %32
30: ; preds = %23, %1
%31 = tail call i32 (i32, i8*, i32, i8*, ...) @TEMP_LOG(i32 2, i8* getelementptr inbounds ([161 x i8], [161 x i8]* @.str, i64 0, i64 0), i32 88, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %32
32: ; preds = %30, %26
%33 = phi i32 [ %28, %26 ], [ -1, %30 ]
ret i32 %33
}