#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*/ EXIT_FAILURE;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
void getChannels(char **chans) {
  assert(NULL != chans);
  unsigned i = 0;
  while (i < 5) {
    fprintf(stdout, "Enter channel (%d left; $ to stop): ", 5 - i);
    if (NULL == fgets(chans[i], 1024, stdin)) {
      perror("fgets error");
      exit(EXIT_FAILURE);
    }
    if ('$' == chans[i][0]) {
      if (0 == i) {
        fprintf(stdout, "At least one channel must be specified\n");
        continue;
      } else
        break;
    }
    i++;
  }
}


x86 assembly (clang, -O0):
<getChannels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x5,-0xc(%rbp)
jae    123a <getChannels+0xea>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    $0x5,%edx
sub    -0xc(%rbp),%edx
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1030 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    11e5 <getChannels+0x95>
lea    0xe53(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%ecx
mov    $0x24,%eax
cmp    %ecx,%eax
jne    122c <getChannels+0xdc>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jne    1227 <getChannels+0xd7>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1176 <getChannels+0x26>
jmp    123a <getChannels+0xea>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1176 <getChannels+0x26>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getChannels>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1040 <assert@plt>
mov    0x2e5d(%rip),%r12
lea    0xe86(%rip),%r14
mov    0x2e67(%rip),%r13
lea    0xea9(%rip),%r15
xor    %ebp,%ebp
jmp    1198 <getChannels+0x48>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x5,%ebp
jae    11e9 <getChannels+0x99>
mov    (%r12),%edi
mov    $0x5,%edx
sub    %ebp,%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%ebp
mov    (%rbx,%rbp,8),%rdi
mov    0x0(%r13),%edx
mov    $0x400,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     11f8 <getChannels+0xa8>
mov    (%rbx,%rbp,8),%rax
cmpb   $0x24,(%rax)
jne    1190 <getChannels+0x40>
test   %rbp,%rbp
jne    11e9 <getChannels+0x99>
mov    (%r12),%edi
xor    %ebp,%ebp
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmp    $0x5,%ebp
jb     1198 <getChannels+0x48>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe26(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [37 x i8] c"Enter channel (%d left; $ to stop): \00"
@stdin = global i32 0
@.str.1 = [12 x i8] c"fgets error\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [40 x i8] c"At least one channel must be specified\0A\00"
define void @getChannels(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
store i8** %0, i8*** %2
%4 = load i8**, i8*** %2
%5 = icmp ne i8** null, %4
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
store i32 0, i32* %3
br label %8
8: ; preds = %45, %41, %1
%9 = load i32, i32* %3
%10 = icmp ult i32 %9, 5
br i1 %10, label %11, label %48
11: ; preds = %8
%12 = load i32, i32* @stdout
%13 = load i32, i32* %3
%14 = sub i32 5, %13
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i8**, i8*** %2
%17 = load i32, i32* %3
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
%20 = load i8*, i8** %19
%21 = load i32, i32* @stdin
%22 = call i32* @fgets(i8* %20, i32 1024, i32 %21)
%23 = icmp eq i32* null, %22
br i1 %23, label %24, label %28
24: ; preds = %11
%25 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %11
%29 = load i8**, i8*** %2
%30 = load i32, i32* %3
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp eq i32 36, %36
br i1 %37, label %38, label %45
38: ; preds = %28
%39 = load i32, i32* %3
%40 = icmp eq i32 0, %39
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* @stdout
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %8
44: ; preds = %38
br label %48
45: ; preds = %28
%46 = load i32, i32* %3
%47 = add i32 %46, 1
store i32 %47, i32* %3
br label %8
48: ; preds = %44, %8
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [37 x i8] c"Enter channel (%d left; $ to stop): \00"
@stdin = global i32 0
@.str.1 = [12 x i8] c"fgets error\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [40 x i8] c"At least one channel must be specified\0A\00"
define void @getChannels(i8** %0) {
%2 = icmp ne i8** %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
br label %5
5: ; preds = %1, %29
%6 = phi i32 [ 0, %1 ], [ %30, %29 ]
%7 = load i32, i32* @stdout
%8 = sub nuw nsw i32 5, %6
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = zext i32 %6 to i64
%11 = getelementptr inbounds i8*, i8** %0, i64 %10
%12 = load i8*, i8** %11
%13 = load i32, i32* @stdin
%14 = tail call i32* @fgets(i8* %12, i32 1024, i32 %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %5
%17 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %5
%21 = load i8*, i8** %11
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 36
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = icmp eq i32 %6, 0
br i1 %25, label %26, label %34
26: ; preds = %24
%27 = load i32, i32* @stdout
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %26, %32
%30 = phi i32 [ 0, %26 ], [ %33, %32 ]
%31 = icmp ult i32 %30, 5
br i1 %31, label %5, label %34
32: ; preds = %20
%33 = add nuw nsw i32 %6, 1
br label %29
34: ; preds = %24, %29
ret void
}