#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*/ FILE;

/* Variables and functions */
char *TCPInstanceStr();
char *USBInstanceStr();
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
scalar_t__ strstr(char *, char *);
char *InstanceStr(void) {
  char *possible_device_names[] = {TCPInstanceStr(), USBInstanceStr()};
  enum {
    kNumDeviceNames =
        sizeof possible_device_names / sizeof possible_device_names[0]
  };
  FILE *adb_devices_cmd_stream = popen("/usr/bin/adb devices", "r");
  char line[128] = {0};
  while (fgets(line, sizeof line, adb_devices_cmd_stream) != NULL) {
    for (int i = 0; i < kNumDeviceNames; ++i) {
      if (strstr(line, possible_device_names[i])) {
        return possible_device_names[i];
      }
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<InstanceStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    $0x0,%al
call   1040 <TCPInstanceStr@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <USBInstanceStr@plt>
mov    %rax,-0x18(%rbp)
lea    0xe78(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x28(%rbp)
lea    -0xb0(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x80,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1236 <InstanceStr+0xd6>
movl   $0x0,-0xb4(%rbp)
cmpl   $0x2,-0xb4(%rbp)
jge    1231 <InstanceStr+0xd1>
lea    -0xb0(%rbp),%rdi
movslq -0xb4(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1218 <InstanceStr+0xb8>
movslq -0xb4(%rbp),%rax
mov    -0x20(%rbp,%rax,8),%rax
mov    %rax,-0x8(%rbp)
jmp    123e <InstanceStr+0xde>
jmp    121d <InstanceStr+0xbd>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    11d4 <InstanceStr+0x74>
jmp    11ab <InstanceStr+0x4b>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<InstanceStr>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
xor    %eax,%eax
call   1040 <TCPInstanceStr@plt>
mov    %rax,%r15
xor    %eax,%eax
call   1030 <USBInstanceStr@plt>
mov    %rax,%r14
lea    0xe87(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,%r12
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1205 <InstanceStr+0xb5>
mov    %rsp,%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
jne    120d <InstanceStr+0xbd>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
jne    120a <InstanceStr+0xba>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r12,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    11d0 <InstanceStr+0x80>
xor    %r15d,%r15d
jmp    120d <InstanceStr+0xbd>
mov    %r14,%r15
mov    %r15,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"/usr/bin/adb devices\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @InstanceStr() {
%1 = alloca i8*
%2 = alloca [2 x i8*]
%3 = alloca i32*
%4 = alloca [128 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%7 = call i8* (...) @TCPInstanceStr()
store i8* %7, i8** %6
%8 = getelementptr inbounds i8*, i8** %6, i64 1
%9 = call i8* (...) @USBInstanceStr()
store i8* %9, i8** %8
%10 = call i32* @popen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %3
%11 = bitcast [128 x i8]* %4 to i8*
br label %12
12: ; preds = %38, %0
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i32* @fgets(i8* %13, i32 128, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %39
17: ; preds = %12
store i32 0, i32* %5
br label %18
18: ; preds = %35, %17
%19 = load i32, i32* %5
%20 = icmp slt i32 %19, 2
br i1 %20, label %21, label %38
21: ; preds = %18
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %24
%26 = load i8*, i8** %25
%27 = call i64 @strstr(i8* %22, i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %21
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 %31
%33 = load i8*, i8** %32
store i8* %33, i8** %1
br label %40
34: ; preds = %21
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %18
38: ; preds = %18
br label %12
39: ; preds = %12
store i8* null, i8** %1
br label %40
40: ; preds = %39, %29
%41 = load i8*, i8** %1
ret i8* %41
}

LLVM IR (-O2):
@.str = [21 x i8] c"/usr/bin/adb devices\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @InstanceStr() {
%1 = alloca [128 x i8]
%2 = tail call i8* (...) @TCPInstanceStr()
%3 = tail call i8* (...) @USBInstanceStr()
%4 = tail call i32* @popen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%6 = call i32* @fgets(i8* %5, i32 128, i32* %4)
%7 = icmp eq i32* %6, null
br i1 %7, label %17, label %8
8: ; preds = %0, %14
%9 = call i64 @strstr(i8* %5, i8* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = call i64 @strstr(i8* %5, i8* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32* @fgets(i8* %5, i32 128, i32* %4)
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %8
17: ; preds = %14, %8, %11, %0
%18 = phi i8* [ null, %0 ], [ null, %14 ], [ %3, %11 ], [ %2, %8 ]
ret i8* %18
}