#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*/ Display;
typedef int /*<<< orphan*/ Bool;

/* Variables and functions */
int /*<<< orphan*/ XFree(char *);
int /*<<< orphan*/ XNVCTRLStringOperation(int /*<<< orphan*/ *, int, int,
                                          int /*<<< orphan*/, int, char *,
                                          char **);
int /*<<< orphan*/ printf(char *, ...);
void do_configure(Display *dpy, int use_gvi, char *pIn) {
  Bool ret;
  char *pOut = NULL;
  if (use_gvi < 0) {
    use_gvi = 0;
  }
  printf("Configuring GVI device %d:\n\n", use_gvi);
  printf("Setting ");
  if (!pIn) {
    pIn = "stream=0, link0=jack0.0; "
          "stream=1, link0=jack1.0; "
          "stream=2, link0=jack2.0; "
          "stream=3, link0=jack3.0";
    printf("default");
  } else {
    printf("custom");
  }
  printf(" configuration:\n\n");
  printf("  \"%s\"\n\n", pIn);
  ret = XNVCTRLStringOperation(dpy, 4, use_gvi, 0, 4, pIn, &pOut);
  if (!ret) {
    printf("  - Failed to configure stream topology of GVI %d.\n", use_gvi);
    return;
  }
  printf("Topology:\n\n");
  printf("  %s\n\n", pOut ? pOut : "No streams are configured.");
  if (pOut) {
    XFree(pOut);
    pOut = NULL;
  }
}


x86 assembly (clang, -O0):
<do_configure>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    115c <do_configure+0x2c>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
jne    11a4 <do_configure+0x74>
lea    0xe99(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xef1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <do_configure+0x82>
lea    0xee6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xedf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%r9
mov    $0x4,%r8d
xor    %ecx,%ecx
lea    -0x28(%rbp),%rax
mov    %r8d,%esi
mov    %rax,(%rsp)
call   1050 <XNVCTRLStringOperation@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1218 <do_configure+0xe8>
mov    -0xc(%rbp),%esi
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    127c <do_configure+0x14c>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     123e <do_configure+0x10e>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    124e <do_configure+0x11e>
lea    0xeb5(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    124e <do_configure+0x11e>
mov    -0x30(%rbp),%rsi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpq   $0x0,-0x28(%rbp)
je     127c <do_configure+0x14c>
mov    -0x28(%rbp),%rdi
call   1040 <XFree@plt>
movq   $0x0,-0x28(%rbp)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_configure>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r14
movq   $0x0,0x10(%rsp)
xor    %eax,%eax
test   %esi,%esi
cmovs  %eax,%ebp
lea    0xe97(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r15,%r15
lea    0xeff(%rip),%rax
lea    0xf00(%rip),%rdi
cmove  %rax,%rdi
lea    0xe8a(%rip),%rbx
cmovne %r15,%rbx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xf49(%rip),%rdi
call   1030 <puts@plt>
lea    0xede(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10(%rsp),%rax
mov    %rax,(%rsp)
mov    %r14,%rdi
mov    $0x4,%esi
mov    %ebp,%edx
xor    %ecx,%ecx
mov    $0x4,%r8d
mov    %rbx,%r9
call   1060 <XNVCTRLStringOperation@plt>
test   %eax,%eax
je     1229 <do_configure+0xe9>
lea    0xf16(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%rax
test   %rax,%rax
lea    0xed6(%rip),%rsi
cmovne %rax,%rsi
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rdi
test   %rdi,%rdi
je     1239 <do_configure+0xf9>
call   1050 <XFree@plt>
jmp    1239 <do_configure+0xf9>
lea    0xe71(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Configuring GVI device %d:\0A\0A\00"
@.str.1 = [9 x i8] c"Setting \00"
@.str.2 = [99 x i8] c"stream=0, link0=jack0.0; stream=1, link0=jack1.0; stream=2, link0=jack2.0; stream=3, link0=jack3.0\00"
@.str.3 = [8 x i8] c"default\00"
@.str.4 = [7 x i8] c"custom\00"
@.str.5 = [18 x i8] c" configuration:\0A\0A\00"
@.str.6 = [9 x i8] c" \22%s\22\0A\0A\00"
@.str.7 = [52 x i8] c" - Failed to configure stream topology of GVI %d.\0A\00"
@.str.8 = [12 x i8] c"Topology:\0A\0A\00"
@.str.9 = [7 x i8] c" %s\0A\0A\00"
@.str.10 = [27 x i8] c"No streams are configured.\00"
define void @do_configure(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i8* null, i8** %8
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 0, i32* %5
br label %12
12: ; preds = %11, %3
%13 = load i32, i32* %5
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %12
store i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.2, i64 0, i64 0), i8** %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %22
20: ; preds = %12
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %20, %18
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%24 = load i8*, i8** %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %4
%27 = load i32, i32* %5
%28 = load i8*, i8** %6
%29 = call i32 @XNVCTRLStringOperation(i32* %26, i32 4, i32 %27, i32 0, i32 4, i8* %28, i8** %8)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %22
%33 = load i32, i32* %5
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0), i32 %33)
br label %50
35: ; preds = %22
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%37 = load i8*, i8** %8
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = load i8*, i8** %8
br label %42
41: ; preds = %35
br label %42
42: ; preds = %41, %39
%43 = phi i8* [ %40, %39 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), %41 ]
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* %43)
%45 = load i8*, i8** %8
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i8*, i8** %8
%49 = call i32 @XFree(i8* %48)
store i8* null, i8** %8
br label %50
50: ; preds = %32, %47, %42
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"Configuring GVI device %d:\0A\0A\00"
@.str.1 = [9 x i8] c"Setting \00"
@.str.2 = [99 x i8] c"stream=0, link0=jack0.0; stream=1, link0=jack1.0; stream=2, link0=jack2.0; stream=3, link0=jack3.0\00"
@.str.3 = [8 x i8] c"default\00"
@.str.4 = [7 x i8] c"custom\00"
@.str.6 = [9 x i8] c" \22%s\22\0A\0A\00"
@.str.7 = [52 x i8] c" - Failed to configure stream topology of GVI %d.\0A\00"
@.str.9 = [7 x i8] c" %s\0A\0A\00"
@.str.10 = [27 x i8] c"No streams are configured.\00"
@str = [17 x i8] c" configuration:\0A\00"
@str.11 = [11 x i8] c"Topology:\0A\00"
define void @do_configure(i32* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = icmp sgt i32 %1, 0
%7 = select i1 %6, i32 %1, i32 0
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %2, null
%11 = select i1 %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0)
%12 = select i1 %10, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.2, i64 0, i64 0), i8* %2
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %11)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%16 = call i32 @XNVCTRLStringOperation(i32* %0, i32 4, i32 %7, i32 0, i32 4, i8* %12, i8** %4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0), i32 %7)
br label %30
20: ; preds = %3
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.11, i64 0, i64 0))
%22 = load i8*, i8** %4
%23 = icmp eq i8* %22, null
%24 = select i1 %23, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i8* %22
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %4
%27 = icmp eq i8* %26, null
br i1 %27, label %30, label %28
28: ; preds = %20
%29 = call i32 @XFree(i8* %26)
br label %30
30: ; preds = %20, %28, %18
ret void
}