#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int snoopy_datasourceregistry_callById(int, char *, char *);
int snoopy_datasourceregistry_getCount();
char *snoopy_datasourceregistry_getName(int);
int /*<<< orphan*/ snoopy_error_handler(char *);
scalar_t__ strcmp(char *, char *);
void snoopy_debug_test_all_datasources() {
  char *itemName = NULL;
  char *itemArgs = NULL;
  char *itemResult = NULL;
  int itemResultSize;
  int i;
  int dCount;
  itemResult = malloc(1024 + 1);
  dCount = snoopy_datasourceregistry_getCount();
  for (i = 0; i < dCount; i++) {
    itemName = snoopy_datasourceregistry_getName(i);
    printf("Datasource %15s: ", itemName);
    if (strcmp(itemName, "env") == 0) {
      itemArgs = "HOME";
    } else if (strcmp(itemName, "snoopy_literal") == 0) {
      itemArgs = "somestring";
    } else {
      itemArgs = "";
    }
    itemResultSize =
        snoopy_datasourceregistry_callById(i, itemResult, itemArgs);
    if (itemResultSize > 1024) {
      snoopy_error_handler("Maximum data source message size exceeded");
    }
    printf("%s\n", itemResult);
  }
  free(itemResult);
}


x86 assembly (clang, -O0):
<snoopy_debug_test_all_datasources>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x401,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <snoopy_datasourceregistry_getCount@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1295 <snoopy_debug_test_all_datasources+0x115>
mov    -0x20(%rbp),%edi
call   1050 <snoopy_datasourceregistry_getName@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe1e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1211 <snoopy_debug_test_all_datasources+0x91>
lea    0xe0e(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    124b <snoopy_debug_test_all_datasources+0xcb>
mov    -0x8(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    123b <snoopy_debug_test_all_datasources+0xbb>
lea    0xdf8(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1246 <snoopy_debug_test_all_datasources+0xc6>
lea    0xe20(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    124b <snoopy_debug_test_all_datasources+0xcb>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1070 <snoopy_datasourceregistry_callById@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x400,-0x1c(%rbp)
jle    1277 <snoopy_debug_test_all_datasources+0xf7>
lea    0xdc3(%rip),%rdi
call   1040 <snoopy_error_handler@plt>
mov    -0x18(%rbp),%rsi
lea    0xddd(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11bf <snoopy_debug_test_all_datasources+0x3f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snoopy_debug_test_all_datasources>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x401,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <snoopy_datasourceregistry_getCount@plt>
test   %eax,%eax
jle    1249 <snoopy_debug_test_all_datasources+0xc9>
mov    %eax,%r14d
lea    0xe63(%rip),%r12
lea    0xea5(%rip),%r13
jmp    11d3 <snoopy_debug_test_all_datasources+0x53>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
je     1249 <snoopy_debug_test_all_datasources+0xc9>
mov    %ebp,%edi
call   1050 <snoopy_datasourceregistry_getName@plt>
mov    %rax,%r15
lea    0xe1c(%rip),%rdi
mov    %rax,%rsi
call   1060 <printf@plt>
mov    %r15,%rdi
lea    0xe1c(%rip),%rsi
call   1080 <strcmp@plt>
mov    %r12,%rdx
test   %rax,%rax
je     1227 <snoopy_debug_test_all_datasources+0xa7>
mov    %r15,%rdi
lea    0xe0e(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
lea    0xe46(%rip),%rdx
lea    0xe07(%rip),%rax
cmove  %rax,%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1070 <snoopy_datasourceregistry_callById@plt>
cmp    $0x401,%eax
jl     11c0 <snoopy_debug_test_all_datasources+0x40>
lea    0xdf6(%rip),%rdi
call   1040 <snoopy_error_handler@plt>
jmp    11c0 <snoopy_debug_test_all_datasources+0x40>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Datasource %15s: \00"
@.str.1 = [4 x i8] c"env\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [15 x i8] c"snoopy_literal\00"
@.str.4 = [11 x i8] c"somestring\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [42 x i8] c"Maximum data source message size exceeded\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define void @snoopy_debug_test_all_datasources() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* null, i8** %1
store i8* null, i8** %2
store i8* null, i8** %3
%7 = call i8* @malloc(i32 1025)
store i8* %7, i8** %3
%8 = call i32 (...) @snoopy_datasourceregistry_getCount()
store i32 %8, i32* %6
store i32 0, i32* %5
br label %9
9: ; preds = %41, %0
%10 = load i32, i32* %5
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %44
13: ; preds = %9
%14 = load i32, i32* %5
%15 = call i8* @snoopy_datasourceregistry_getName(i32 %14)
store i8* %15, i8** %1
%16 = load i8*, i8** %1
%17 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %1
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %13
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %29
22: ; preds = %13
%23 = load i8*, i8** %1
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %28
27: ; preds = %22
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %28
28: ; preds = %27, %26
br label %29
29: ; preds = %28, %21
%30 = load i32, i32* %5
%31 = load i8*, i8** %3
%32 = load i8*, i8** %2
%33 = call i32 @snoopy_datasourceregistry_callById(i32 %30, i8* %31, i8* %32)
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = icmp sgt i32 %34, 1024
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 @snoopy_error_handler(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
br label %38
38: ; preds = %36, %29
%39 = load i8*, i8** %3
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38
%42 = load i32, i32* %5
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
br label %9
44: ; preds = %9
%45 = load i8*, i8** %3
%46 = call i32 @free(i8* %45)
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"Datasource %15s: \00"
@.str.1 = [4 x i8] c"env\00"
@.str.2 = [5 x i8] c"HOME\00"
@.str.3 = [15 x i8] c"snoopy_literal\00"
@.str.4 = [11 x i8] c"somestring\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [42 x i8] c"Maximum data source message size exceeded\00"
@.str.7 = [4 x i8] c"%s\0A\00"
define void @snoopy_debug_test_all_datasources() {
%1 = tail call dereferenceable_or_null(1025) i8* @malloc(i32 1025)
%2 = tail call i32 (...) @snoopy_datasourceregistry_getCount()
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %24
4: ; preds = %0, %20
%5 = phi i32 [ %22, %20 ], [ 0, %0 ]
%6 = tail call i8* @snoopy_datasourceregistry_getName(i32 %5)
%7 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0)
br label %14
14: ; preds = %10, %4
%15 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %4 ], [ %13, %10 ]
%16 = tail call i32 @snoopy_datasourceregistry_callById(i32 %5, i8* %1, i8* %15)
%17 = icmp sgt i32 %16, 1024
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 @snoopy_error_handler(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
br label %20
20: ; preds = %18, %14
%21 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %1)
%22 = add nuw nsw i32 %5, 1
%23 = icmp eq i32 %22, %2
br i1 %23, label %24, label %4
24: ; preds = %20, %0
%25 = tail call i32 @free(i8* %1)
ret void
}