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

/* Variables and functions */
int /*<<< orphan*/ buildDigCmd(char *, char *, char *, char *, char *, char *,
                               char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int formatModelIdentifier(char *, char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
scalar_t__ strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
int deviceInfoForHost(char *host, char *hostIP, char *devInfo) {
  FILE *in;
  extern FILE *popen();
  char buff[512];
  char address[512];
  char command[1024] = "";
  int returnValue = 0;
  if (hostIP == NULL || strcmp(hostIP, "") == 0) {
    strcpy(address, "");
  } else {
    strcpy(address, hostIP);
  }
  buildDigCmd(address, host, "5353", "_device-info._tcp", "local", "TXT",
              command);
  if (!(in = popen(command, "r"))) {
    returnValue = 1;
  } else {
    while (fgets(buff, sizeof(buff), in) != NULL) {
      char *token;
      token = strtok(buff, " ");
      char modelID[64] = "";
      int found = 0;
      while (token != NULL) {
        if (strchr(token, '=') != 0) {
          strcpy(modelID, token);
          found = 1;
          break;
        }
        token = strtok(NULL, " ");
      }
      if (!found) {
        strcpy(devInfo, "");
        returnValue = 1;
      } else {
        returnValue = formatModelIdentifier(modelID, devInfo);
        break;
      }
    }
  }
  pclose(in);
  return returnValue;
}


x86 assembly (clang, -O0):
<deviceInfoForHost>:
push   %rbp
mov    %rsp,%rbp
sub    $0x880,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
movl   $0x0,-0x824(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11f9 <deviceInfoForHost+0x59>
mov    -0x10(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1211 <deviceInfoForHost+0x71>
lea    -0x420(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1221 <deviceInfoForHost+0x81>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x820(%rbp),%rax
lea    0xdc6(%rip),%rdx
lea    0xdc4(%rip),%rcx
lea    0xdcf(%rip),%r8
lea    0xdce(%rip),%r9
mov    %rax,(%rsp)
call   1040 <buildDigCmd@plt>
lea    -0x820(%rbp),%rdi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   10b0 <popen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    128a <deviceInfoForHost+0xea>
movl   $0x1,-0x824(%rbp)
jmp    139d <deviceInfoForHost+0x1fd>
jmp    128f <deviceInfoForHost+0xef>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x200,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1398 <deviceInfoForHost+0x1f8>
lea    -0x220(%rbp),%rdi
lea    0xd67(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x830(%rbp)
lea    -0x870(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
movl   $0x0,-0x874(%rbp)
cmpq   $0x0,-0x830(%rbp)
je     134c <deviceInfoForHost+0x1ac>
mov    -0x830(%rbp),%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
je     1330 <deviceInfoForHost+0x190>
lea    -0x870(%rbp),%rdi
mov    -0x830(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x874(%rbp)
jmp    134c <deviceInfoForHost+0x1ac>
xor    %eax,%eax
mov    %eax,%edi
lea    0xce8(%rip),%rsi
call   10c0 <strtok@plt>
mov    %rax,-0x830(%rbp)
jmp    12e5 <deviceInfoForHost+0x145>
cmpl   $0x0,-0x874(%rbp)
jne    1378 <deviceInfoForHost+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xcc0(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x824(%rbp)
jmp    1393 <deviceInfoForHost+0x1f3>
lea    -0x870(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <formatModelIdentifier@plt>
mov    %eax,-0x824(%rbp)
jmp    1398 <deviceInfoForHost+0x1f8>
jmp    128f <deviceInfoForHost+0xef>
jmp    139d <deviceInfoForHost+0x1fd>
mov    -0x20(%rbp),%rdi
call   1060 <pclose@plt>
mov    -0x824(%rbp),%eax
add    $0x880,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deviceInfoForHost>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x858,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0x450(%rsp),%r15
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1070 <memset@plt>
test   %rbp,%rbp
je     11f4 <deviceInfoForHost+0x54>
lea    0xe47(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     11f4 <deviceInfoForHost+0x54>
lea    0x50(%rsp),%rdi
mov    %rbp,%rsi
jmp    1200 <deviceInfoForHost+0x60>
lea    0xe29(%rip),%rsi
lea    0x50(%rsp),%rdi
call   1030 <strcpy@plt>
mov    %r15,(%rsp)
lea    0xdf0(%rip),%rdx
lea    0xdee(%rip),%rcx
lea    0xdf9(%rip),%r8
lea    0xdf8(%rip),%r9
lea    0x50(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <buildDigCmd@plt>
lea    0xde8(%rip),%rsi
xor    %ebx,%ebx
mov    %r15,%rdi
xor    %eax,%eax
call   10b0 <popen@plt>
mov    %rax,%r15
test   %rax,%rax
je     1306 <deviceInfoForHost+0x166>
lea    0x250(%rsp),%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     132a <deviceInfoForHost+0x18a>
lea    0xdad(%rip),%rbx
lea    0x250(%rsp),%r12
lea    0xd9f(%rip),%r13
jmp    12b0 <deviceInfoForHost+0x110>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
mov    $0x200,%esi
mov    %r15,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
je     1306 <deviceInfoForHost+0x166>
mov    %r12,%rdi
mov    %rbx,%rsi
call   10c0 <strtok@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
test   %rax,%rax
je     1290 <deviceInfoForHost+0xf0>
mov    %rax,%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x3d,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    130d <deviceInfoForHost+0x16d>
xor    %edi,%edi
mov    %rbx,%rsi
call   10c0 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    12e0 <deviceInfoForHost+0x140>
jmp    1290 <deviceInfoForHost+0xf0>
mov    $0x1,%ebx
jmp    132a <deviceInfoForHost+0x18a>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <formatModelIdentifier@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <pclose@plt>
mov    %ebx,%eax
add    $0x858,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"5353\00"
@.str.2 = [18 x i8] c"_device-info._tcp\00"
@.str.3 = [6 x i8] c"local\00"
@.str.4 = [4 x i8] c"TXT\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [2 x i8] c" \00"
define i32 @deviceInfoForHost(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [512 x i8]
%9 = alloca [512 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i32
%12 = alloca i8*
%13 = alloca [64 x i8]
%14 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%15 = bitcast [1024 x i8]* %10 to i8*
store i32 0, i32* %11
%16 = load i8*, i8** %5
%17 = icmp eq i8* %16, null
br i1 %17, label %22, label %18
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18, %3
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%24 = call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %29
25: ; preds = %18
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = call i32 @strcpy(i8* %26, i8* %27)
br label %29
29: ; preds = %25, %22
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%31 = load i8*, i8** %4
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%33 = call i32 @buildDigCmd(i8* %30, i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%35 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %35, i32** %7
%36 = icmp ne i32* %35, null
br i1 %36, label %38, label %37
37: ; preds = %29
store i32 1, i32* %11
br label %73
38: ; preds = %29
br label %39
39: ; preds = %71, %38
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%41 = load i32*, i32** %7
%42 = call i32* @fgets(i8* %40, i32 512, i32* %41)
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %72
44: ; preds = %39
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%46 = call i8* @strtok(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %46, i8** %12
%47 = bitcast [64 x i8]* %13 to i8*
store i32 0, i32* %14
br label %48
48: ; preds = %59, %44
%49 = load i8*, i8** %12
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %61
51: ; preds = %48
%52 = load i8*, i8** %12
%53 = call i64 @strchr(i8* %52, i8 signext 61)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %51
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%57 = load i8*, i8** %12
%58 = call i32 @strcpy(i8* %56, i8* %57)
store i32 1, i32* %14
br label %61
59: ; preds = %51
%60 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i8* %60, i8** %12
br label %48
61: ; preds = %55, %48
%62 = load i32, i32* %14
%63 = icmp ne i32 %62, 0
br i1 %63, label %67, label %64
64: ; preds = %61
%65 = load i8*, i8** %6
%66 = call i32 @strcpy(i8* %65, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %11
br label %71
67: ; preds = %61
%68 = getelementptr inbounds [64 x i8], [64 x i8]* %13, i64 0, i64 0
%69 = load i8*, i8** %6
%70 = call i32 @formatModelIdentifier(i8* %68, i8* %69)
store i32 %70, i32* %11
br label %72
71: ; preds = %64
br label %39
72: ; preds = %67, %39
br label %73
73: ; preds = %72, %37
%74 = load i32*, i32** %7
%75 = call i32 @pclose(i32* %74)
%76 = load i32, i32* %11
ret i32 %76
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [5 x i8] c"5353\00"
@.str.2 = [18 x i8] c"_device-info._tcp\00"
@.str.3 = [6 x i8] c"local\00"
@.str.4 = [4 x i8] c"TXT\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [2 x i8] c" \00"
define i32 @deviceInfoForHost(i8* %0, i8* %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = alloca [512 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [64 x i8]
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = icmp eq i8* %1, null
br i1 %11, label %15, label %12
12: ; preds = %3
%13 = tail call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12, %3
%16 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %19
17: ; preds = %12
%18 = call i32 @strcpy(i8* %9, i8* %1)
br label %19
19: ; preds = %17, %15
%20 = call i32 @buildDigCmd(i8* %9, i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %10)
%21 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %45, label %23
23: ; preds = %19
%24 = call i32* @fgets(i8* %8, i32 512, i32* %21)
%25 = icmp eq i32* %24, null
br i1 %25, label %45, label %26
26: ; preds = %23
%27 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
br label %28
28: ; preds = %26, %41
%29 = call i8* @strtok(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%30 = icmp eq i8* %29, null
br i1 %30, label %41, label %31
31: ; preds = %28, %35
%32 = phi i8* [ %36, %35 ], [ %29, %28 ]
%33 = call i64 @strchr(i8* %32, i8 signext 61)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%37 = icmp eq i8* %36, null
br i1 %37, label %41, label %31
38: ; preds = %31
%39 = call i32 @strcpy(i8* %27, i8* %32)
%40 = call i32 @formatModelIdentifier(i8* %27, i8* %2)
br label %45
41: ; preds = %35, %28
%42 = call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%43 = call i32* @fgets(i8* %8, i32 512, i32* %21)
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %28
45: ; preds = %41, %23, %38, %19
%46 = phi i32 [ 1, %19 ], [ %40, %38 ], [ 0, %23 ], [ 1, %41 ]
%47 = call i32 @pclose(i32* %21)
ret i32 %46
}