#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 MIDIMessage {
  int dummy;
};
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ MIDIMessageEncode(struct MIDIMessage *, int, unsigned char *,
                                     size_t *);
int /*<<< orphan*/ printf(char *, ...);
int _recv(void *interface, struct MIDIMessage *message) {
  size_t i, size;
  unsigned char buffer[8];
  printf("Received MIDI message\n");
  MIDIMessageEncode(message, sizeof(buffer), buffer, &size);
  for (i = 0; i < size; i++) {
    if (i != size - 1)
      printf("0x%02x ", buffer[i]);
    else
      printf("0x%02x\n", buffer[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rdx
mov    $0x8,%esi
lea    -0x20(%rbp),%rcx
call   1040 <MIDIMessageEncode@plt>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11c8 <_recv+0xa8>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
je     119b <_recv+0x7b>
mov    -0x18(%rbp),%rax
movzbl -0x28(%rbp,%rax,1),%esi
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b2 <_recv+0x92>
mov    -0x18(%rbp),%rax
movzbl -0x28(%rbp,%rax,1),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b7 <_recv+0x97>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    115c <_recv+0x3c>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_recv>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
lea    0x8(%rsp),%rdx
mov    %rsp,%rcx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1050 <MIDIMessageEncode@plt>
mov    (%rsp),%rax
test   %rax,%rax
je     11a7 <_recv+0x77>
lea    0xe9b(%rip),%r14
lea    0xe8c(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%rax
cmp    %rax,%rbx
movzbl 0x8(%rsp,%rbx,1),%esi
mov    %r15,%rdi
cmove  %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
mov    (%rsp),%rax
cmp    %rax,%rbx
jb     1180 <_recv+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.MIDIMessage = type { i32 }
@.str = [23 x i8] c"Received MIDI message\0A\00"
@.str.1 = [8 x i8] c"0x%02x \00"
@.str.2 = [8 x i8] c"0x%02x\0A\00"
define i32 @_recv(i8* %0, %struct.MIDIMessage* %1) {
%3 = alloca i8*
%4 = alloca %struct.MIDIMessage*
%5 = alloca i64
%6 = alloca i64
%7 = alloca [8 x i8]
store i8* %0, i8** %3
store %struct.MIDIMessage* %1, %struct.MIDIMessage** %4
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%9 = load %struct.MIDIMessage*, %struct.MIDIMessage** %4
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%11 = call i32 @MIDIMessageEncode(%struct.MIDIMessage* %9, i32 8, i8* %10, i64* %6)
store i64 0, i64* %5
br label %12
12: ; preds = %34, %2
%13 = load i64, i64* %5
%14 = load i64, i64* %6
%15 = icmp ult i64 %13, %14
br i1 %15, label %16, label %37
16: ; preds = %12
%17 = load i64, i64* %5
%18 = load i64, i64* %6
%19 = sub i64 %18, 1
%20 = icmp ne i64 %17, %19
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i64, i64* %5
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %33
27: ; preds = %16
%28 = load i64, i64* %5
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %27, %21
br label %34
34: ; preds = %33
%35 = load i64, i64* %5
%36 = add i64 %35, 1
store i64 %36, i64* %5
br label %12
37: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
%struct.MIDIMessage = type { i32 }
@.str.1 = [8 x i8] c"0x%02x \00"
@.str.2 = [8 x i8] c"0x%02x\0A\00"
@str = [22 x i8] c"Received MIDI message\00"
define i32 @_recv(i8* nocapture readnone %0, %struct.MIDIMessage* %1) {
%3 = alloca i64
%4 = alloca [8 x i8]
%5 = bitcast i64* %3 to i8*
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%8 = call i32 @MIDIMessageEncode(%struct.MIDIMessage* %1, i32 8, i8* %6, i64* %3)
%9 = load i64, i64* %3
%10 = icmp eq i64 %9, 0
br i1 %10, label %24, label %11
11: ; preds = %2, %11
%12 = phi i64 [ %22, %11 ], [ %9, %2 ]
%13 = phi i64 [ %21, %11 ], [ 0, %2 ]
%14 = add i64 %12, -1
%15 = icmp eq i64 %13, %14
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 %13
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = select i1 %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %19, i32 %18)
%21 = add nuw i64 %13, 1
%22 = load i64, i64* %3
%23 = icmp ult i64 %21, %22
br i1 %23, label %11, label %24
24: ; preds = %11, %2
ret i32 0
}