#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 */
struct pcm {
  int dummy;
};
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
struct pcm *get_pcm_in();
struct pcm *get_pcm_out();
int pcm_get_buffer_size(struct pcm *);
int pcm_read(struct pcm *, unsigned char *, int);
int /*<<< orphan*/ pcm_write(struct pcm *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
void loopback() {
  struct pcm *pcm_out = get_pcm_out();
  struct pcm *pcm_in = get_pcm_in();
  unsigned char buff[128];
  if (!pcm_out || !pcm_in)
    return;
  printf("buffer size:%d %d\n", pcm_get_buffer_size(pcm_out),
         pcm_get_buffer_size(pcm_in));
  while (1) {
    int ret = pcm_read(pcm_in, buff, sizeof(buff));
    if (!ret) {
      if (!pcm_write(pcm_out, buff, sizeof(buff))) {
      } else {
        break;
      }
    } else {
      break;
    }
  }
  printf("exit!\n");
}


x86 assembly (clang, -O0):
<loopback>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    $0x0,%al
call   1080 <get_pcm_out@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1070 <get_pcm_in@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1197 <loopback+0x37>
cmpq   $0x0,-0x10(%rbp)
jne    119c <loopback+0x3c>
jmp    1237 <loopback+0xd7>
mov    -0x8(%rbp),%rdi
call   1050 <pcm_get_buffer_size@plt>
mov    %eax,-0x98(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <pcm_get_buffer_size@plt>
mov    -0x98(%rbp),%esi
mov    %eax,%edx
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1030 <pcm_read@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0x0,-0x94(%rbp)
jne    121f <loopback+0xbf>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1060 <pcm_write@plt>
cmp    $0x0,%eax
jne    1215 <loopback+0xb5>
jmp    121a <loopback+0xba>
jmp    1229 <loopback+0xc9>
jmp    1224 <loopback+0xc4>
jmp    1229 <loopback+0xc9>
jmp    11ca <loopback+0x6a>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loopback>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
xor    %eax,%eax
call   1090 <get_pcm_out@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1080 <get_pcm_in@plt>
test   %r14,%r14
je     1204 <loopback+0x94>
mov    %rax,%r15
test   %rax,%rax
je     1204 <loopback+0x94>
mov    %r14,%rdi
call   1060 <pcm_get_buffer_size@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <pcm_get_buffer_size@plt>
lea    0xe4d(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1030 <pcm_read@plt>
test   %eax,%eax
jne    11f8 <loopback+0x88>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1070 <pcm_write@plt>
test   %eax,%eax
je     11d0 <loopback+0x60>
lea    0xe14(%rip),%rdi
call   1040 <puts@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.pcm = type { i32 }
@.str = [19 x i8] c"buffer size:%d %d\0A\00"
@.str.1 = [7 x i8] c"exit!\0A\00"
define void @loopback() {
%1 = alloca %struct.pcm*
%2 = alloca %struct.pcm*
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = call %struct.pcm* (...) @get_pcm_out()
store %struct.pcm* %5, %struct.pcm** %1
%6 = call %struct.pcm* (...) @get_pcm_in()
store %struct.pcm* %6, %struct.pcm** %2
%7 = load %struct.pcm*, %struct.pcm** %1
%8 = icmp ne %struct.pcm* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load %struct.pcm*, %struct.pcm** %2
%11 = icmp ne %struct.pcm* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9, %0
br label %37
13: ; preds = %9
%14 = load %struct.pcm*, %struct.pcm** %1
%15 = call i32 @pcm_get_buffer_size(%struct.pcm* %14)
%16 = load %struct.pcm*, %struct.pcm** %2
%17 = call i32 @pcm_get_buffer_size(%struct.pcm* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %17)
br label %19
19: ; preds = %13, %34
%20 = load %struct.pcm*, %struct.pcm** %2
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%22 = call i32 @pcm_read(%struct.pcm* %20, i8* %21, i32 128)
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp ne i32 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %19
%26 = load %struct.pcm*, %struct.pcm** %1
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%28 = call i32 @pcm_write(%struct.pcm* %26, i8* %27, i32 128)
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25
br label %32
31: ; preds = %25
br label %35
32: ; preds = %30
br label %34
33: ; preds = %19
br label %35
34: ; preds = %32
br label %19
35: ; preds = %33, %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %12
ret void
}

LLVM IR (-O2):
%struct.pcm = type { i32 }
@.str = [19 x i8] c"buffer size:%d %d\0A\00"
@str = [6 x i8] c"exit!\00"
define void @loopback() {
%1 = alloca [128 x i8]
%2 = tail call %struct.pcm* (...) @get_pcm_out()
%3 = tail call %struct.pcm* (...) @get_pcm_in()
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = icmp ne %struct.pcm* %2, null
%6 = icmp ne %struct.pcm* %3, null
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %8, label %20
8: ; preds = %0
%9 = tail call i32 @pcm_get_buffer_size(%struct.pcm* %2)
%10 = tail call i32 @pcm_get_buffer_size(%struct.pcm* %3)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
br label %12
12: ; preds = %15, %8
%13 = call i32 @pcm_read(%struct.pcm* %3, i8* %4, i32 128)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @pcm_write(%struct.pcm* %2, i8* %4, i32 128)
%17 = icmp eq i32 %16, 0
br i1 %17, label %12, label %18
18: ; preds = %15, %12
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %0, %18
ret void
}