#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*/ str;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int winusbtmc_get_device_count();
int /*<<< orphan*/ winusbtmc_get_device_string(int, char *, int);
void list_devices(void) {
  int i;
  int32_t devicecount = 0;
  char str[256];
  devicecount = winusbtmc_get_device_count();
  printf("%d winusbtmc device(s) present.\n", devicecount);
  for (i = 0; i < devicecount; i++) {
    winusbtmc_get_device_string(i, (char *)str, sizeof(str));
    printf("Device #%d: \"%s\"\n", i, str);
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<list_devices>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <winusbtmc_get_device_count@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11aa <list_devices+0x7a>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1050 <winusbtmc_get_device_string@plt>
mov    -0x4(%rbp),%esi
lea    -0x110(%rbp),%rdx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1164 <list_devices+0x34>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_devices>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
xor    %eax,%eax
call   1040 <winusbtmc_get_device_count@plt>
mov    %eax,%r15d
lea    0xea2(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
test   %r15d,%r15d
jle    11a6 <list_devices+0x66>
mov    %rsp,%rbx
lea    0xeab(%rip),%r14
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1060 <winusbtmc_get_device_string@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    1180 <list_devices+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"%d winusbtmc device(s) present.\0A\00"
@.str.1 = [18 x i8] c"Device #%d: \22%s\22\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @list_devices() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [256 x i8]
store i32 0, i32* %2
%4 = call i32 (...) @winusbtmc_get_device_count()
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 0, i32* %1
br label %7
7: ; preds = %18, %0
%8 = load i32, i32* %1
%9 = load i32, i32* %2
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %21
11: ; preds = %7
%12 = load i32, i32* %1
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%14 = call i32 @winusbtmc_get_device_string(i32 %12, i8* %13, i32 256)
%15 = load i32, i32* %1
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %15, i8* %16)
br label %18
18: ; preds = %11
%19 = load i32, i32* %1
%20 = add nsw i32 %19, 1
store i32 %20, i32* %1
br label %7
21: ; preds = %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [33 x i8] c"%d winusbtmc device(s) present.\0A\00"
@.str.1 = [18 x i8] c"Device #%d: \22%s\22\0A\00"
define void @list_devices() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @winusbtmc_get_device_count()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %12
6: ; preds = %0, %6
%7 = phi i32 [ %10, %6 ], [ 0, %0 ]
%8 = call i32 @winusbtmc_get_device_string(i32 %7, i8* %2, i32 256)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %7, i8* %2)
%10 = add nuw nsw i32 %7, 1
%11 = icmp eq i32 %10, %3
br i1 %11, label %12, label %6
12: ; preds = %6, %0
%13 = call i32 @putchar(i32 10)
ret void
}