#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 *, ...);
int snoopy_outputregistry_callById(int, char *, int, char *);
int snoopy_outputregistry_getCount();
char *snoopy_outputregistry_getName(int);
int /*<<< orphan*/ snprintf(char *, int, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ unlink(char *);
void snoopy_debug_test_all_outputs() {
  char *message = NULL;
  char *itemName = NULL;
  char *itemArgs = NULL;
  int itemResult;
  int iCount;
  int i;
  message = malloc(16383 + 1);
  snprintf(message, 16383, "Snoopy output debugging");
  iCount = snoopy_outputregistry_getCount();
  for (i = 0; i < iCount; i++) {
    itemName = snoopy_outputregistry_getName(i);
    printf("Output %19s: ", itemName);
    if (strcmp(itemName, "file") == 0) {
      itemArgs = "./fileoutput.out";
    } else if (strcmp(itemName, "socket") == 0) {
      itemArgs = "/dev/log";
    } else {
      itemArgs = "";
    }
    itemResult = snoopy_outputregistry_callById(i, message, 2, itemArgs);
    printf("%d chars transmitted. (output arg:%s)\n", itemResult, itemArgs);
    if (strcmp(itemName, "file") == 0) {
      unlink(itemArgs);
    }
  }
  free(message);
}


x86 assembly (clang, -O0):
<snoopy_debug_test_all_outputs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x4000,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3fff,%esi
lea    0xe32(%rip),%rdx
call   1070 <snprintf@plt>
mov    $0x0,%al
call   1080 <snoopy_outputregistry_getCount@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12d5 <snoopy_debug_test_all_outputs+0x145>
mov    -0x24(%rbp),%edi
call   1060 <snoopy_outputregistry_getName@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1238 <snoopy_debug_test_all_outputs+0xa8>
lea    0xdfc(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1272 <snoopy_debug_test_all_outputs+0xe2>
mov    -0x10(%rbp),%rdi
lea    0xdf9(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1262 <snoopy_debug_test_all_outputs+0xd2>
lea    0xdea(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    126d <snoopy_debug_test_all_outputs+0xdd>
lea    0xe09(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1272 <snoopy_debug_test_all_outputs+0xe2>
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x2,%edx
call   10b0 <snoopy_outputregistry_callById@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xd7c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12c2 <snoopy_debug_test_all_outputs+0x132>
mov    -0x18(%rbp),%rdi
call   1040 <unlink@plt>
jmp    12c7 <snoopy_debug_test_all_outputs+0x137>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e4 <snoopy_debug_test_all_outputs+0x54>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snoopy_debug_test_all_outputs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x4000,%edi
call   10a0 <malloc@plt>
mov    %rax,%r15
lea    0xe51(%rip),%rdx
mov    %rax,%rdi
mov    $0x3fff,%esi
call   1070 <snprintf@plt>
xor    %eax,%eax
call   1080 <snoopy_outputregistry_getCount@plt>
test   %eax,%eax
jle    128a <snoopy_debug_test_all_outputs+0xfa>
mov    %eax,%ebp
lea    0xe52(%rip),%rbx
xor    %r13d,%r13d
jmp    121f <snoopy_debug_test_all_outputs+0x8f>
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x2,%edx
mov    %r12,%rcx
call   10b0 <snoopy_outputregistry_callById@plt>
lea    0xe52(%rip),%rdi
mov    %eax,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1280 <snoopy_debug_test_all_outputs+0xf0>
add    $0x1,%r13d
cmp    %r13d,%ebp
je     128a <snoopy_debug_test_all_outputs+0xfa>
mov    %r13d,%edi
call   1060 <snoopy_outputregistry_getName@plt>
mov    %rax,%r14
lea    0xde7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcmp@plt>
lea    0xdde(%rip),%r12
test   %rax,%rax
je     11e0 <snoopy_debug_test_all_outputs+0x50>
mov    %r14,%rdi
lea    0xde0(%rip),%rsi
call   1090 <strcmp@plt>
lea    0xddb(%rip),%r12
test   %rax,%rax
je     11e0 <snoopy_debug_test_all_outputs+0x50>
lea    0xdfa(%rip),%r12
jmp    11e0 <snoopy_debug_test_all_outputs+0x50>
nopl   (%rax)
mov    %r12,%rdi
call   1040 <unlink@plt>
jmp    1216 <snoopy_debug_test_all_outputs+0x86>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [24 x i8] c"Snoopy output debugging\00"
@.str.1 = [14 x i8] c"Output %19s: \00"
@.str.2 = [5 x i8] c"file\00"
@.str.3 = [17 x i8] c"./fileoutput.out\00"
@.str.4 = [7 x i8] c"socket\00"
@.str.5 = [9 x i8] c"/dev/log\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [39 x i8] c"%d chars transmitted. (output arg:%s)\0A\00"
define void @snoopy_debug_test_all_outputs() {
%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 16384)
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = call i32 @snprintf(i8* %8, i32 16383, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @snoopy_outputregistry_getCount()
store i32 %10, i32* %5
store i32 0, i32* %6
br label %11
11: ; preds = %46, %0
%12 = load i32, i32* %6
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %49
15: ; preds = %11
%16 = load i32, i32* %6
%17 = call i8* @snoopy_outputregistry_getName(i32 %16)
store i8* %17, i8** %2
%18 = load i8*, i8** %2
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %2
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %15
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %31
24: ; preds = %15
%25 = load i8*, i8** %2
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8** %3
br label %30
29: ; preds = %24
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), i8** %3
br label %30
30: ; preds = %29, %28
br label %31
31: ; preds = %30, %23
%32 = load i32, i32* %6
%33 = load i8*, i8** %1
%34 = load i8*, i8** %3
%35 = call i32 @snoopy_outputregistry_callById(i32 %32, i8* %33, i32 2, i8* %34)
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = load i8*, i8** %3
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i32 %36, i8* %37)
%39 = load i8*, i8** %2
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %31
%43 = load i8*, i8** %3
%44 = call i32 @unlink(i8* %43)
br label %45
45: ; preds = %42, %31
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %11
49: ; preds = %11
%50 = load i8*, i8** %1
%51 = call i32 @free(i8* %50)
ret void
}

LLVM IR (-O2):
@.str = [24 x i8] c"Snoopy output debugging\00"
@.str.1 = [14 x i8] c"Output %19s: \00"
@.str.2 = [5 x i8] c"file\00"
@.str.3 = [17 x i8] c"./fileoutput.out\00"
@.str.4 = [7 x i8] c"socket\00"
@.str.5 = [9 x i8] c"/dev/log\00"
@.str.6 = [1 x i8] zeroinitializer
@.str.7 = [39 x i8] c"%d chars transmitted. (output arg:%s)\0A\00"
define void @snoopy_debug_test_all_outputs() {
%1 = tail call dereferenceable_or_null(16384) i8* @malloc(i32 16384)
%2 = tail call i32 @snprintf(i8* %1, i32 16383, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (...) @snoopy_outputregistry_getCount()
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %26
5: ; preds = %0, %23
%6 = phi i32 [ %24, %23 ], [ 0, %0 ]
%7 = tail call i8* @snoopy_outputregistry_getName(i32 %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %5
%12 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0)
br label %15
15: ; preds = %11, %5
%16 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), %5 ], [ %14, %11 ]
%17 = tail call i32 @snoopy_outputregistry_callById(i32 %6, i8* %1, i32 2, i8* %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.7, i64 0, i64 0), i32 %17, i8* %16)
%19 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = tail call i32 @unlink(i8* %16)
br label %23
23: ; preds = %15, %21
%24 = add nuw nsw i32 %6, 1
%25 = icmp eq i32 %24, %3
br i1 %25, label %26, label %5
26: ; preds = %23, %0
%27 = tail call i32 @free(i8* %1)
ret void
}