#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*/ _dbprintf(char *, char *, int, ...);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ ishouse(char);
int strlen(char *);
char *strtok(int /*<<< orphan*/ *, char *);
int getdeviceaddr(int *unit) {
  char *parm, c;
  int house = -1;
  *unit = -1;
  parm = strtok(NULL, " ");
  if (!parm || (strlen(parm) > 3))
    return house;
  _dbprintf(
      "deviceaddr %s\n",
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/SensorFlare/mochad/refs/heads/master/encode.c",
      292, parm);
  c = *parm++;
  if (!ishouse(c))
    return house;
  house = c - 'A';
  _dbprintf(
      "house %d\n",
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/SensorFlare/mochad/refs/heads/master/encode.c",
      297, house);
  c = *parm++;
  if (!isdigit(c))
    return house;
  *unit = c - '0';
  _dbprintf(
      "*unit %d\n",
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/SensorFlare/mochad/refs/heads/master/encode.c",
      302, *unit);
  c = *parm++;
  if (!isdigit(c)) {
    (*unit)--;
    _dbprintf("*unit %d\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/SensorFlare/mochad/refs/heads/master/"
              "encode.c",
              307, *unit);
    return house;
  }
  *unit = (*unit * 10) + (c - '0');
  if (*unit > 16) {
    *unit = -1;
    return house;
  }
  (*unit)--;
  return house;
}


x86 assembly (clang, -O0):
<getdeviceaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe88(%rip),%rsi
call   1070 <strtok@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119e <getdeviceaddr+0x4e>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x3,%eax
jle    11a9 <getdeviceaddr+0x59>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1322 <getdeviceaddr+0x1d2>
mov    -0x18(%rbp),%rcx
lea    0xe4e(%rip),%rdi
lea    0xe56(%rip),%rsi
mov    $0x124,%edx
mov    $0x0,%al
call   1040 <_dbprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%edi
call   1060 <ishouse@plt>
cmp    $0x0,%eax
jne    11f8 <getdeviceaddr+0xa8>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1322 <getdeviceaddr+0x1d2>
movsbl -0x19(%rbp),%eax
sub    $0x41,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
lea    0xe8d(%rip),%rdi
lea    0xdfe(%rip),%rsi
mov    $0x129,%edx
mov    $0x0,%al
call   1040 <_dbprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1250 <getdeviceaddr+0x100>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1322 <getdeviceaddr+0x1d2>
movsbl -0x19(%rbp),%ecx
sub    $0x30,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xe39(%rip),%rdi
lea    0xda0(%rip),%rsi
mov    $0x12e,%edx
mov    $0x0,%al
call   1040 <_dbprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x19(%rbp)
movsbl -0x19(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    12d9 <getdeviceaddr+0x189>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xde8(%rip),%rdi
lea    0xd4f(%rip),%rsi
mov    $0x133,%edx
mov    $0x0,%al
call   1040 <_dbprintf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1322 <getdeviceaddr+0x1d2>
mov    -0x10(%rbp),%rax
imul   $0xa,(%rax),%ecx
movsbl -0x19(%rbp),%eax
sub    $0x30,%eax
add    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x10,(%rax)
jle    1311 <getdeviceaddr+0x1c1>
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1322 <getdeviceaddr+0x1d2>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0xffffffff,%ecx
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdeviceaddr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
movl   $0xffffffff,(%rdi)
lea    0xe99(%rip),%rsi
xor    %edi,%edi
call   1070 <strtok@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
je     1268 <getdeviceaddr+0x118>
mov    %rax,%rbp
mov    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x3,%eax
jg     1268 <getdeviceaddr+0x118>
lea    0xe6b(%rip),%rdi
lea    0xe73(%rip),%rsi
mov    $0x124,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1040 <_dbprintf@plt>
movsbl 0x0(%rbp),%r14d
mov    %r14d,%edi
call   1060 <ishouse@plt>
test   %eax,%eax
je     1268 <getdeviceaddr+0x118>
add    $0xffffffbf,%r14d
lea    0xecc(%rip),%rdi
lea    0xe3d(%rip),%rsi
mov    $0x129,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1040 <_dbprintf@plt>
movsbl 0x1(%rbp),%ebx
mov    %ebx,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1265 <getdeviceaddr+0x115>
add    $0xffffffd0,%ebx
mov    %ebx,(%r15)
lea    0xea4(%rip),%rdi
lea    0xe0b(%rip),%rsi
mov    $0x12e,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <_dbprintf@plt>
movsbl 0x2(%rbp),%ebx
mov    %ebx,%edi
call   1030 <isdigit@plt>
mov    (%r15),%ecx
test   %eax,%eax
je     123d <getdeviceaddr+0xed>
lea    (%rcx,%rcx,4),%eax
lea    (%rbx,%rax,2),%eax
add    $0xffffffd0,%eax
cmp    $0x11,%eax
jl     125f <getdeviceaddr+0x10f>
movl   $0xffffffff,(%r15)
jmp    1265 <getdeviceaddr+0x115>
add    $0xffffffff,%ecx
mov    %ecx,(%r15)
lea    0xe59(%rip),%rdi
lea    0xdc0(%rip),%rsi
mov    $0x133,%edx
xor    %eax,%eax
call   1040 <_dbprintf@plt>
jmp    1265 <getdeviceaddr+0x115>
add    $0xffffffff,%eax
mov    %eax,(%r15)
mov    %r14d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [15 x i8] c"deviceaddr %s\0A\00"
@.str.2 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/SensorFlare/mochad/refs/heads/master/encode.c\00"
@.str.3 = [10 x i8] c"house %d\0A\00"
@.str.4 = [10 x i8] c"*unit %d\0A\00"
define i32 @getdeviceaddr(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
store i32* %0, i32** %3
store i32 -1, i32* %6
%7 = load i32*, i32** %3
store i32 -1, i32* %7
%8 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 3
br i1 %14, label %15, label %17
15: ; preds = %11, %1
%16 = load i32, i32* %6
store i32 %16, i32* %2
br label %84
17: ; preds = %11
%18 = load i8*, i8** %4
%19 = call i32 (i8*, i8*, i32, ...) @_dbprintf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 292, i8* %18)
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8, i8* %20
store i8 %22, i8* %5
%23 = load i8, i8* %5
%24 = call i32 @ishouse(i8 signext %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %17
%27 = load i32, i32* %6
store i32 %27, i32* %2
br label %84
28: ; preds = %17
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = sub nsw i32 %30, 65
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = call i32 (i8*, i8*, i32, ...) @_dbprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 297, i32 %32)
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
%36 = load i8, i8* %34
store i8 %36, i8* %5
%37 = load i8, i8* %5
%38 = call i32 @isdigit(i8 signext %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %42, label %40
40: ; preds = %28
%41 = load i32, i32* %6
store i32 %41, i32* %2
br label %84
42: ; preds = %28
%43 = load i8, i8* %5
%44 = sext i8 %43 to i32
%45 = sub nsw i32 %44, 48
%46 = load i32*, i32** %3
store i32 %45, i32* %46
%47 = load i32*, i32** %3
%48 = load i32, i32* %47
%49 = call i32 (i8*, i8*, i32, ...) @_dbprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 302, i32 %48)
%50 = load i8*, i8** %4
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %4
%52 = load i8, i8* %50
store i8 %52, i8* %5
%53 = load i8, i8* %5
%54 = call i32 @isdigit(i8 signext %53)
%55 = icmp ne i32 %54, 0
br i1 %55, label %64, label %56
56: ; preds = %42
%57 = load i32*, i32** %3
%58 = load i32, i32* %57
%59 = add nsw i32 %58, -1
store i32 %59, i32* %57
%60 = load i32*, i32** %3
%61 = load i32, i32* %60
%62 = call i32 (i8*, i8*, i32, ...) @_dbprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 307, i32 %61)
%63 = load i32, i32* %6
store i32 %63, i32* %2
br label %84
64: ; preds = %42
%65 = load i32*, i32** %3
%66 = load i32, i32* %65
%67 = mul nsw i32 %66, 10
%68 = load i8, i8* %5
%69 = sext i8 %68 to i32
%70 = sub nsw i32 %69, 48
%71 = add nsw i32 %67, %70
%72 = load i32*, i32** %3
store i32 %71, i32* %72
%73 = load i32*, i32** %3
%74 = load i32, i32* %73
%75 = icmp sgt i32 %74, 16
br i1 %75, label %76, label %79
76: ; preds = %64
%77 = load i32*, i32** %3
store i32 -1, i32* %77
%78 = load i32, i32* %6
store i32 %78, i32* %2
br label %84
79: ; preds = %64
%80 = load i32*, i32** %3
%81 = load i32, i32* %80
%82 = add nsw i32 %81, -1
store i32 %82, i32* %80
%83 = load i32, i32* %6
store i32 %83, i32* %2
br label %84
84: ; preds = %79, %76, %56, %40, %26, %15
%85 = load i32, i32* %2
ret i32 %85
}

LLVM IR (-O2):
@.str = [2 x i8] c" \00"
@.str.1 = [15 x i8] c"deviceaddr %s\0A\00"
@.str.2 = [136 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/SensorFlare/mochad/refs/heads/master/encode.c\00"
@.str.3 = [10 x i8] c"house %d\0A\00"
@.str.4 = [10 x i8] c"*unit %d\0A\00"
define i32 @getdeviceaddr(i32* nocapture %0) {
store i32 -1, i32* %0
%2 = tail call i8* @strtok(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %41, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %2)
%6 = icmp sgt i32 %5, 3
br i1 %6, label %41, label %7
7: ; preds = %4
%8 = tail call i32 (i8*, i8*, i32, ...) @_dbprintf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 292, i8* %2)
%9 = load i8, i8* %2
%10 = tail call i32 @ishouse(i8 signext %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %41, label %12
12: ; preds = %7
%13 = getelementptr inbounds i8, i8* %2, i64 1
%14 = sext i8 %9 to i32
%15 = add nsw i32 %14, -65
%16 = tail call i32 (i8*, i8*, i32, ...) @_dbprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 297, i32 %15)
%17 = load i8, i8* %13
%18 = tail call i32 @isdigit(i8 signext %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %41, label %20
20: ; preds = %12
%21 = getelementptr inbounds i8, i8* %2, i64 2
%22 = sext i8 %17 to i32
%23 = add nsw i32 %22, -48
store i32 %23, i32* %0
%24 = tail call i32 (i8*, i8*, i32, ...) @_dbprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 302, i32 %23)
%25 = load i8, i8* %21
%26 = tail call i32 @isdigit(i8 signext %25)
%27 = icmp eq i32 %26, 0
%28 = load i32, i32* %0
br i1 %27, label %29, label %32
29: ; preds = %20
%30 = add nsw i32 %28, -1
store i32 %30, i32* %0
%31 = tail call i32 (i8*, i8*, i32, ...) @_dbprintf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([136 x i8], [136 x i8]* @.str.2, i64 0, i64 0), i32 307, i32 %30)
br label %41
32: ; preds = %20
%33 = mul nsw i32 %28, 10
%34 = sext i8 %25 to i32
%35 = add nsw i32 %34, -48
%36 = add nsw i32 %35, %33
%37 = icmp sgt i32 %36, 16
br i1 %37, label %38, label %39
38: ; preds = %32
store i32 -1, i32* %0
br label %41
39: ; preds = %32
%40 = add nsw i32 %36, -1
store i32 %40, i32* %0
br label %41
41: ; preds = %12, %7, %1, %4, %39, %38, %29
%42 = phi i32 [ %15, %38 ], [ %15, %39 ], [ %15, %29 ], [ -1, %4 ], [ -1, %1 ], [ -1, %7 ], [ %15, %12 ]
ret i32 %42
}