#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ hddtemp_connect(char const *, int, char *, int);
char *split(char *, int);
scalar_t__ strcmp(char const *, char *);
char *hddtemp_fetch(const char *host, int port, const char *device) {
  char buffer[4096];
  char *key;
  int i;
  if (!hddtemp_connect(host, port, buffer, sizeof(buffer))) {
    return "err";
  }
  i = 1;
  while (1) {
    key = split(buffer, i);
    if (key == NULL)
      break;
    if (strcmp(device, key) == 0) {
      return split(buffer, i + 2);
    }
    i += 5;
  }
  return "n/a";
}


x86 assembly (clang, -O0):
<hddtemp_fetch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x1020(%rbp),%rdx
mov    $0x1000,%ecx
call   1030 <hddtemp_connect@plt>
cmp    $0x0,%eax
jne    1177 <hddtemp_fetch+0x47>
lea    0xe92(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1204 <hddtemp_fetch+0xd4>
movl   $0x1,-0x102c(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x102c(%rbp),%esi
call   1040 <split@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jne    11ad <hddtemp_fetch+0x7d>
jmp    11f9 <hddtemp_fetch+0xc9>
mov    -0x20(%rbp),%rdi
mov    -0x1028(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11e5 <hddtemp_fetch+0xb5>
lea    -0x1020(%rbp),%rdi
mov    -0x102c(%rbp),%esi
add    $0x2,%esi
call   1040 <split@plt>
mov    %rax,-0x8(%rbp)
jmp    1204 <hddtemp_fetch+0xd4>
mov    -0x102c(%rbp),%eax
add    $0x5,%eax
mov    %eax,-0x102c(%rbp)
jmp    1181 <hddtemp_fetch+0x51>
lea    0xe04(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hddtemp_fetch>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rdx,%r15
mov    %rsp,%rdx
mov    $0x1000,%ecx
call   1030 <hddtemp_connect@plt>
test   %eax,%eax
je     11a5 <hddtemp_fetch+0x75>
mov    %rsp,%rdi
mov    $0x1,%esi
call   1040 <split@plt>
lea    0xe9e(%rip),%r14
test   %rax,%rax
je     11bb <hddtemp_fetch+0x8b>
mov    $0x3,%ebx
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ae <hddtemp_fetch+0x7e>
lea    0x3(%rbx),%esi
mov    %r12,%rdi
call   1040 <split@plt>
add    $0x5,%ebx
test   %rax,%rax
jne    1180 <hddtemp_fetch+0x50>
jmp    11bb <hddtemp_fetch+0x8b>
lea    0xe54(%rip),%r14
jmp    11bb <hddtemp_fetch+0x8b>
mov    %rsp,%rdi
mov    %ebx,%esi
call   1040 <split@plt>
mov    %rax,%r14
mov    %r14,%rax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"err\00"
@.str.1 = [4 x i8] c"n/a\00"
define i8* @hddtemp_fetch(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [4096 x i8]
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%14 = call i32 @hddtemp_connect(i8* %11, i32 %12, i8* %13, i32 4096)
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %4
br label %39
17: ; preds = %3
store i32 1, i32* %10
br label %18
18: ; preds = %17, %35
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%20 = load i32, i32* %10
%21 = call i8* @split(i8* %19, i32 %20)
store i8* %21, i8** %9
%22 = load i8*, i8** %9
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %18
br label %38
25: ; preds = %18
%26 = load i8*, i8** %7
%27 = load i8*, i8** %9
%28 = call i64 @strcmp(i8* %26, i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 2
%34 = call i8* @split(i8* %31, i32 %33)
store i8* %34, i8** %4
br label %39
35: ; preds = %25
%36 = load i32, i32* %10
%37 = add nsw i32 %36, 5
store i32 %37, i32* %10
br label %18
38: ; preds = %24
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %4
br label %39
39: ; preds = %38, %30, %16
%40 = load i8*, i8** %4
ret i8* %40
}

LLVM IR (-O2):
@.str = [4 x i8] c"err\00"
@.str.1 = [4 x i8] c"n/a\00"
define i8* @hddtemp_fetch(i8* %0, i32 %1, i8* %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = call i32 @hddtemp_connect(i8* %0, i32 %1, i8* %5, i32 4096)
%7 = icmp eq i32 %6, 0
br i1 %7, label %23, label %8
8: ; preds = %3
%9 = call i8* @split(i8* %5, i32 1)
%10 = icmp eq i8* %9, null
br i1 %10, label %23, label %11
11: ; preds = %8, %19
%12 = phi i8* [ %21, %19 ], [ %9, %8 ]
%13 = phi i32 [ %20, %19 ], [ 1, %8 ]
%14 = call i64 @strcmp(i8* %2, i8* %12)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = add nuw nsw i32 %13, 2
%18 = call i8* @split(i8* %5, i32 %17)
br label %23
19: ; preds = %11
%20 = add nuw nsw i32 %13, 5
%21 = call i8* @split(i8* %5, i32 %20)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %11
23: ; preds = %19, %8, %3, %16
%24 = phi i8* [ %18, %16 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %19 ]
ret i8* %24
}