#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*/ CheckError(int /*<<< orphan*/);
int /*<<< orphan*/ LeddarListSensors(char *, unsigned int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
void ListSensors(char *aConnectyionType, char *aAddresses, unsigned int aSize) {
  char lConnectionType[256];
  unsigned int lIndex = 0;
  if (aConnectyionType == NULL) {
    printf("\nEnter the connection type (USB or SERIAL): ");
    scanf("%255s", lConnectionType);
  } else {
    strcpy(lConnectionType, aConnectyionType);
  }
  strcpy(aAddresses, aConnectyionType);
  CheckError(LeddarListSensors(aAddresses, &aSize));
  printf("\nFound %d sensors of type %s\n", aSize, lConnectionType);
  int lConnectionFoundIndex = 0;
  while (strlen(aAddresses + lIndex) > 0) {
    if (lConnectionFoundIndex % 2 == 0) {
      if (strcmp(aConnectyionType, "USB") != 0) {
        printf("%d : %s", lConnectionFoundIndex / 2, aAddresses + lIndex);
      } else {
        printf("%d : ", lConnectionFoundIndex / 2);
      }
    } else {
      if (strcmp(aConnectyionType, "USB") != 0) {
        printf("\t[ %s ]\n", aAddresses + lIndex);
      } else {
        printf("[ %s ]\n", aAddresses + lIndex);
      }
    }
    lConnectionFoundIndex++;
    lIndex += strlen(aAddresses + lIndex) + 1;
  }
}


x86 assembly (clang, -O0):
<ListSensors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x124(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11c1 <ListSensors+0x51>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1090 <scanf@plt>
jmp    11d1 <ListSensors+0x61>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1080 <LeddarListSensors@plt>
mov    %eax,%edi
call   1040 <CheckError@plt>
mov    -0x14(%rbp),%esi
lea    -0x120(%rbp),%rdx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x128(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x124(%rbp),%eax
add    %rax,%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jle    134a <ListSensors+0x1da>
mov    -0x128(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    12b4 <ListSensors+0x144>
mov    -0x8(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1291 <ListSensors+0x121>
mov    -0x128(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
mov    -0x124(%rbp),%eax
add    %rax,%rdx
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12af <ListSensors+0x13f>
mov    -0x128(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    130e <ListSensors+0x19e>
mov    -0x8(%rbp),%rdi
lea    0xd92(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12ee <ListSensors+0x17e>
mov    -0x10(%rbp),%rsi
mov    -0x124(%rbp),%eax
add    %rax,%rsi
lea    0xd81(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1309 <ListSensors+0x199>
mov    -0x10(%rbp),%rsi
mov    -0x124(%rbp),%eax
add    %rax,%rsi
lea    0xd62(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    130e <ListSensors+0x19e>
mov    -0x128(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x128(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x124(%rbp),%eax
add    %rax,%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
mov    -0x124(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x124(%rbp)
jmp    1214 <ListSensors+0xa4>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ListSensors>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbp
mov    %rdi,%r14
mov    %edx,0xc(%rsp)
test   %rdi,%rdi
je     119f <ListSensors+0x2f>
lea    0x10(%rsp),%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    11be <ListSensors+0x4e>
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe79(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1090 <scanf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xc(%rsp),%rsi
mov    %rbp,%rdi
call   1080 <LeddarListSensors@plt>
mov    %eax,%edi
call   1040 <CheckError@plt>
mov    0xc(%rsp),%esi
lea    0xe4b(%rip),%rdi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jle    129e <ListSensors+0x12e>
lea    0xe45(%rip),%r15
mov    %rbp,%rbx
xor    %r13d,%r13d
xor    %r12d,%r12d
jmp    124e <ListSensors+0xde>
lea    0xe46(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%r12d
mov    %rbx,%rdi
call   1050 <strlen@plt>
add    %eax,%r13d
add    $0x1,%r13d
mov    %rbp,%rbx
add    %r13,%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
jle    129e <ListSensors+0x12e>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   $0x1,%r12b
jne    1280 <ListSensors+0x110>
mov    %r12d,%esi
shr    %esi
test   %rax,%rax
je     128e <ListSensors+0x11e>
lea    0xde5(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1228 <ListSensors+0xb8>
nopl   0x0(%rax)
test   %rax,%rax
je     1217 <ListSensors+0xa7>
lea    0xdd7(%rip),%rdi
jmp    121e <ListSensors+0xae>
lea    0xdc8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1228 <ListSensors+0xb8>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"\0AEnter the connection type (USB or SERIAL): \00"
@.str.1 = [6 x i8] c"%255s\00"
@.str.2 = [30 x i8] c"\0AFound %d sensors of type %s\0A\00"
@.str.3 = [4 x i8] c"USB\00"
@.str.4 = [8 x i8] c"%d : %s\00"
@.str.5 = [6 x i8] c"%d : \00"
@.str.6 = [9 x i8] c"\09[ %s ]\0A\00"
@.str.7 = [8 x i8] c"[ %s ]\0A\00"
define void @ListSensors(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %8
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%15 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %14)
br label %20
16: ; preds = %3
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = call i32 @strcpy(i8* %17, i8* %18)
br label %20
20: ; preds = %16, %12
%21 = load i8*, i8** %5
%22 = load i8*, i8** %4
%23 = call i32 @strcpy(i8* %21, i8* %22)
%24 = load i8*, i8** %5
%25 = call i32 @LeddarListSensors(i8* %24, i32* %6)
%26 = call i32 @CheckError(i32 %25)
%27 = load i32, i32* %6
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %27, i8* %28)
store i32 0, i32* %9
br label %30
30: ; preds = %75, %20
%31 = load i8*, i8** %5
%32 = load i32, i32* %8
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = call i64 @strlen(i8* %34)
%36 = icmp sgt i64 %35, 0
br i1 %36, label %37, label %88
37: ; preds = %30
%38 = load i32, i32* %9
%39 = srem i32 %38, 2
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %58
41: ; preds = %37
%42 = load i8*, i8** %4
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = load i32, i32* %9
%47 = sdiv i32 %46, 2
%48 = load i8*, i8** %5
%49 = load i32, i32* %8
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %47, i8* %51)
br label %57
53: ; preds = %41
%54 = load i32, i32* %9
%55 = sdiv i32 %54, 2
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %53, %45
br label %75
58: ; preds = %37
%59 = load i8*, i8** %4
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %68
62: ; preds = %58
%63 = load i8*, i8** %5
%64 = load i32, i32* %8
%65 = zext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %63, i64 %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %66)
br label %74
68: ; preds = %58
%69 = load i8*, i8** %5
%70 = load i32, i32* %8
%71 = zext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %69, i64 %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %68, %62
br label %75
75: ; preds = %74, %57
%76 = load i32, i32* %9
%77 = add nsw i32 %76, 1
store i32 %77, i32* %9
%78 = load i8*, i8** %5
%79 = load i32, i32* %8
%80 = zext i32 %79 to i64
%81 = getelementptr inbounds i8, i8* %78, i64 %80
%82 = call i64 @strlen(i8* %81)
%83 = add nsw i64 %82, 1
%84 = load i32, i32* %8
%85 = zext i32 %84 to i64
%86 = add nsw i64 %85, %83
%87 = trunc i64 %86 to i32
store i32 %87, i32* %8
br label %30
88: ; preds = %30
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"\0AEnter the connection type (USB or SERIAL): \00"
@.str.1 = [6 x i8] c"%255s\00"
@.str.2 = [30 x i8] c"\0AFound %d sensors of type %s\0A\00"
@.str.3 = [4 x i8] c"USB\00"
@.str.4 = [8 x i8] c"%d : %s\00"
@.str.5 = [6 x i8] c"%d : \00"
@.str.6 = [9 x i8] c"\09[ %s ]\0A\00"
@.str.7 = [8 x i8] c"[ %s ]\0A\00"
define void @ListSensors(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca [256 x i8]
store i32 %2, i32* %4
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %0, null
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %13
11: ; preds = %3
%12 = call i32 @strcpy(i8* %6, i8* %0)
br label %13
13: ; preds = %11, %8
%14 = call i32 @strcpy(i8* %1, i8* %0)
%15 = call i32 @LeddarListSensors(i8* %1, i32* %4)
%16 = call i32 @CheckError(i32 %15)
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %17, i8* %6)
%19 = call i64 @strlen(i8* dereferenceable(1) %1)
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %49
21: ; preds = %13, %40
%22 = phi i8* [ %46, %40 ], [ %1, %13 ]
%23 = phi i64 [ %45, %40 ], [ 0, %13 ]
%24 = phi i32 [ %41, %40 ], [ 0, %13 ]
%25 = and i32 %24, 1
%26 = icmp eq i32 %25, 0
%27 = call i64 @strcmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %26, label %29, label %35
29: ; preds = %21
%30 = lshr i32 %24, 1
br i1 %28, label %33, label %31
31: ; preds = %29
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %30, i8* %22)
br label %40
33: ; preds = %29
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %30)
br label %40
35: ; preds = %21
br i1 %28, label %38, label %36
36: ; preds = %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %22)
br label %40
38: ; preds = %35
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* %22)
br label %40
40: ; preds = %36, %38, %31, %33
%41 = add nuw nsw i32 %24, 1
%42 = call i64 @strlen(i8* dereferenceable(1) %22)
%43 = add nuw nsw i64 %23, 1
%44 = add i64 %43, %42
%45 = and i64 %44, 4294967295
%46 = getelementptr inbounds i8, i8* %1, i64 %45
%47 = call i64 @strlen(i8* dereferenceable(1) %46)
%48 = icmp sgt i64 %47, 0
br i1 %48, label %21, label %49
49: ; preds = %40, %13
ret void
}