#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*/ fd_set;
typedef int /*<<< orphan*/ audiobuf;
typedef int /*<<< orphan*/ astresp;

/* Variables and functions */
scalar_t__ FD_ISSET(scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ STDERR_FILENO;
scalar_t__ STDIN_FILENO;
int /*<<< orphan*/ errno;
scalar_t__ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int read(scalar_t__, char *, int);
int select(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
char *wait_result(void) {
  fd_set fds;
  int res;
  int bytes = 0;
  static char astresp[256];
  char audiobuf[4096];
  for (;;) {
    FD_ZERO(&fds);
    FD_SET(STDIN_FILENO, &fds);
    FD_SET((STDERR_FILENO + 1), &fds);
    res = select((STDERR_FILENO + 1) + 1, &fds, NULL, NULL, NULL);
    if (res < 0) {
      fprintf(stderr, "Error in select: %s\n", strerror(errno));
      return NULL;
    }
    if (FD_ISSET(STDIN_FILENO, &fds)) {
      fgets(astresp, sizeof(astresp), stdin);
      if (feof(stdin)) {
        fprintf(stderr, "Got hungup on apparently\n");
        return NULL;
      }
      astresp[strlen(astresp) - 1] = '\0';
      fprintf(stderr, "Ooh, got a response from Asterisk: '%s'\n", astresp);
      return astresp;
    }
    if (FD_ISSET((STDERR_FILENO + 1), &fds)) {
      res = read((STDERR_FILENO + 1), audiobuf, sizeof(audiobuf));
      if (res > 0) {
        bytes += res;
        if (bytes > 16000 * 3) {
          return "Sample Message";
          bytes = 0;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<wait_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x14(%rbp)
lea    -0xc(%rbp),%rdi
call   1090 <FD_ZERO@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%rdi
lea    -0xc(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
lea    -0xc(%rbp),%rsi
call   10c0 <FD_SET@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
add    $0x1,%rdi
lea    -0xc(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   10a0 <select@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1259 <wait_result+0xb9>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1024(%rbp)
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x1024(%rbp),%edi
mov    %rax,%rdx
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1399 <wait_result+0x1f9>
mov    0x2d60(%rip),%rax
mov    (%rax),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1317 <wait_result+0x177>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
lea    0x2dfa(%rip),%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     12cc <wait_result+0x12c>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd5d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1399 <wait_result+0x1f9>
lea    0x2dad(%rip),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2d9b(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
lea    0xd36(%rip),%rsi
lea    0x2d80(%rip),%rdx
mov    $0x0,%al
call   1070 <fprintf@plt>
lea    0x2d72(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1399 <wait_result+0x1f9>
mov    0x2caa(%rip),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
lea    -0xc(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1394 <wait_result+0x1f4>
mov    0x2c89(%rip),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    138f <wait_result+0x1ef>
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xbb80,-0x14(%rbp)
jle    138a <wait_result+0x1ea>
lea    0xcd7(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1399 <wait_result+0x1f9>
jmp    138f <wait_result+0x1ef>
jmp    1394 <wait_result+0x1f4>
jmp    11b2 <wait_result+0x12>
mov    -0x8(%rbp),%rax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_result>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
xor    %r12d,%r12d
lea    0xc(%rsp),%rbx
mov    0x2e00(%rip),%r13
mov    0x2e01(%rip),%rbp
lea    0x10(%rsp),%r15
lea    0xe85(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1090 <FD_ZERO@plt>
mov    0x0(%r13),%rdi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    0x0(%rbp),%rdi
add    $0x1,%rdi
mov    %rbx,%rsi
call   10c0 <FD_SET@plt>
mov    0x0(%rbp),%rdi
add    $0x2,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10a0 <select@plt>
test   %eax,%eax
js     1273 <wait_result+0xd3>
mov    0x0(%r13),%rdi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
jne    129b <wait_result+0xfb>
mov    0x0(%rbp),%rdi
add    $0x1,%rdi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
test   %rax,%rax
je     11e0 <wait_result+0x40>
mov    0x0(%rbp),%rdi
add    $0x1,%rdi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11e0 <wait_result+0x40>
add    %eax,%r12d
cmp    $0xbb81,%r12d
jl     11e0 <wait_result+0x40>
jmp    130a <wait_result+0x16a>
mov    0x2d5e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd6f(%rip),%rsi
xor    %r14d,%r14d
mov    %ebx,%edi
mov    %rax,%rdx
jmp    1303 <wait_result+0x163>
mov    0x2d46(%rip),%rbx
mov    (%rbx),%edx
lea    0x2dd5(%rip),%r14
mov    %r14,%rdi
mov    $0x100,%esi
call   1060 <fgets@plt>
mov    (%rbx),%edi
call   1080 <feof@plt>
test   %rax,%rax
je     12e0 <wait_result+0x140>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    130a <wait_result+0x16a>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd2f(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@wait_result.astresp = internal global [256 x i8] zeroinitializer
@STDIN_FILENO = global i64 0
@STDERR_FILENO = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"Error in select: %s\0A\00"
@errno = global i32 0
@stdin = global i32 0
@.str.1 = [26 x i8] c"Got hungup on apparently\0A\00"
@.str.2 = [41 x i8] c"Ooh, got a response from Asterisk: '%s'\0A\00"
@.str.3 = [15 x i8] c"Sample Message\00"
define i8* @wait_result() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4096 x i8]
store i32 0, i32* %4
br label %6
6: ; preds = %65, %0
%7 = call i32 @FD_ZERO(i32* %2)
%8 = load i64, i64* @STDIN_FILENO
%9 = call i32 @FD_SET(i64 %8, i32* %2)
%10 = load i64, i64* @STDERR_FILENO
%11 = add nsw i64 %10, 1
%12 = call i32 @FD_SET(i64 %11, i32* %2)
%13 = load i64, i64* @STDERR_FILENO
%14 = add nsw i64 %13, 1
%15 = add nsw i64 %14, 1
%16 = call i32 @select(i64 %15, i32* %2, i32* null, i32* null, i32* null)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %6
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %22)
store i8* null, i8** %1
br label %66
24: ; preds = %6
%25 = load i64, i64* @STDIN_FILENO
%26 = call i64 @FD_ISSET(i64 %25, i32* %2)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %44
28: ; preds = %24
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @wait_result.astresp, i64 0, i64 0), i32 256, i32 %29)
%31 = load i32, i32* @stdin
%32 = call i64 @feof(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %28
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %1
br label %66
37: ; preds = %28
%38 = call i32 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @wait_result.astresp, i64 0, i64 0))
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [256 x i8], [256 x i8]* @wait_result.astresp, i64 0, i64 %40
store i8 0, i8* %41
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @wait_result.astresp, i64 0, i64 0))
store i8* getelementptr inbounds ([256 x i8], [256 x i8]* @wait_result.astresp, i64 0, i64 0), i8** %1
br label %66
44: ; preds = %24
%45 = load i64, i64* @STDERR_FILENO
%46 = add nsw i64 %45, 1
%47 = call i64 @FD_ISSET(i64 %46, i32* %2)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %65
49: ; preds = %44
%50 = load i64, i64* @STDERR_FILENO
%51 = add nsw i64 %50, 1
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%53 = call i32 @read(i64 %51, i8* %52, i32 4096)
store i32 %53, i32* %3
%54 = load i32, i32* %3
%55 = icmp sgt i32 %54, 0
br i1 %55, label %56, label %64
56: ; preds = %49
%57 = load i32, i32* %3
%58 = load i32, i32* %4
%59 = add nsw i32 %58, %57
store i32 %59, i32* %4
%60 = load i32, i32* %4
%61 = icmp sgt i32 %60, 48000
br i1 %61, label %62, label %63
62: ; preds = %56
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %66
63: ; preds = %56
br label %64
64: ; preds = %63, %49
br label %65
65: ; preds = %64, %44
br label %6
66: ; preds = %62, %37, %34, %19
%67 = load i8*, i8** %1
ret i8* %67
}

LLVM IR (-O2):
@wait_result.astresp = internal global [256 x i8] zeroinitializer
@STDIN_FILENO = global i64 0
@STDERR_FILENO = global i64 0
@stderr = global i32 0
@.str = [21 x i8] c"Error in select: %s\0A\00"
@errno = global i32 0
@stdin = global i32 0
@.str.1 = [26 x i8] c"Got hungup on apparently\0A\00"
@.str.2 = [41 x i8] c"Ooh, got a response from Asterisk: '%s'\0A\00"
@.str.3 = [15 x i8] c"Sample Message\00"
define i8* @wait_result() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
br label %5
5: ; preds = %54, %0
%6 = phi i32 [ %55, %54 ], [ 0, %0 ]
br label %7
7: ; preds = %53, %5
%8 = call i32 @FD_ZERO(i32* %1)
%9 = load i64, i64* @STDIN_FILENO
%10 = call i32 @FD_SET(i64 %9, i32* %1)
%11 = load i64, i64* @STDERR_FILENO
%12 = add nsw i64 %11, 1
%13 = call i32 @FD_SET(i64 %12, i32* %1)
%14 = load i64, i64* @STDERR_FILENO
%15 = add nsw i64 %14, 2
%16 = call i32 @select(i64 %15, i32* %1, i32* null, i32* null, i32* null)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %7
%19 = load i32, i32* @stderr
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %57
23: ; preds = %7
%24 = load i64, i64* @STDIN_FILENO
%25 = call i64 @FD_ISSET(i64 %24, i32* %1)
%26 = icmp eq i64 %25, 0
br i1 %26, label %43, label %27
27: ; preds = %23
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @wait_result.astresp, i64 0, i64 0), i32 256, i32 %28)
%30 = load i32, i32* @stdin
%31 = call i64 @feof(i32 %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %57
36: ; preds = %27
%37 = call i32 @strlen(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @wait_result.astresp, i64 0, i64 0))
%38 = add nsw i32 %37, -1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [256 x i8], [256 x i8]* @wait_result.astresp, i64 0, i64 %39
store i8 0, i8* %40
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([256 x i8], [256 x i8]* @wait_result.astresp, i64 0, i64 0))
br label %57
43: ; preds = %23
%44 = load i64, i64* @STDERR_FILENO
%45 = add nsw i64 %44, 1
%46 = call i64 @FD_ISSET(i64 %45, i32* %1)
%47 = icmp eq i64 %46, 0
br i1 %47, label %53, label %48
48: ; preds = %43
%49 = load i64, i64* @STDERR_FILENO
%50 = add nsw i64 %49, 1
%51 = call i32 @read(i64 %50, i8* %4, i32 4096)
%52 = icmp sgt i32 %51, 0
br i1 %52, label %54, label %53
53: ; preds = %48, %43
br label %7
54: ; preds = %48
%55 = add nsw i32 %51, %6
%56 = icmp sgt i32 %55, 48000
br i1 %56, label %57, label %5
57: ; preds = %54, %36, %33, %18
%58 = phi i8* [ null, %18 ], [ null, %33 ], [ getelementptr inbounds ([256 x i8], [256 x i8]* @wait_result.astresp, i64 0, i64 0), %36 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %54 ]
ret i8* %58
}