#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 */
scalar_t__ MYread_char(int, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ write(int, char *, int);
int passon(int source, int dest, int n) {
  char *p;
  int i;
  p = (char *)malloc(n);
  if (!p) {
    perror("Out of memory\n");
    exit(1);
  }
  if (n) {
    for (i = 0; i < n; i++)
      if (MYread_char(source, &p[i]) < 0)
        return -1;
    write(dest, p, n);
  }
  free(p);
  return 0;
}


x86 assembly (clang, -O0):
<passon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    119e <passon+0x3e>
lea    0xe71(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x10(%rbp)
je     1206 <passon+0xa6>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11f7 <passon+0x97>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
call   1050 <MYread_char@plt>
cmp    $0x0,%rax
jge    11e4 <passon+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <passon+0xb6>
jmp    11e9 <passon+0x89>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11af <passon+0x4f>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1040 <write@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<passon>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %esi,%r15d
mov    %edi,%r13d
mov    %edx,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11d8 <passon+0x78>
mov    %rax,%r14
test   %r12d,%r12d
je     11b8 <passon+0x58>
jle    11aa <passon+0x4a>
mov    %r12d,%ebp
mov    %r14,%rbx
mov    %r13d,%edi
mov    %rbx,%rsi
call   1050 <MYread_char@plt>
test   %rax,%rax
js     11d1 <passon+0x71>
add    $0x1,%rbx
add    $0xffffffffffffffff,%rbp
jne    1190 <passon+0x30>
mov    %r15d,%edi
mov    %r14,%rsi
mov    %r12d,%edx
call   1040 <write@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%eax
jmp    11c2 <passon+0x62>
lea    0xe21(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Out of memory\0A\00"
define i32 @passon(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
%11 = call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %8
%13 = load i8*, i8** %8
%14 = icmp ne i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = load i32, i32* %7
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %44
21: ; preds = %18
store i32 0, i32* %9
br label %22
22: ; preds = %36, %21
%23 = load i32, i32* %9
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = load i32, i32* %5
%28 = load i8*, i8** %8
%29 = load i32, i32* %9
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = call i64 @MYread_char(i32 %27, i8* %31)
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %26
store i32 -1, i32* %4
br label %47
35: ; preds = %26
br label %36
36: ; preds = %35
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %22
39: ; preds = %22
%40 = load i32, i32* %6
%41 = load i8*, i8** %8
%42 = load i32, i32* %7
%43 = call i32 @write(i32 %40, i8* %41, i32 %42)
br label %44
44: ; preds = %39, %18
%45 = load i8*, i8** %8
%46 = call i32 @free(i8* %45)
store i32 0, i32* %4
br label %47
47: ; preds = %44, %34
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@.str = [15 x i8] c"Out of memory\0A\00"
define i32 @passon(i32 %0, i32 %1, i32 %2) {
%4 = tail call i64 @malloc(i32 %2)
%5 = inttoptr i64 %4 to i8*
%6 = icmp eq i64 %4, 0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = icmp eq i32 %2, 0
br i1 %11, label %26, label %12
12: ; preds = %10
%13 = icmp sgt i32 %2, 0
br i1 %13, label %14, label %24
14: ; preds = %12
%15 = zext i32 %2 to i64
br label %18
16: ; preds = %18
%17 = icmp eq i64 %23, %15
br i1 %17, label %24, label %18
18: ; preds = %14, %16
%19 = phi i64 [ 0, %14 ], [ %23, %16 ]
%20 = getelementptr inbounds i8, i8* %5, i64 %19
%21 = tail call i64 @MYread_char(i32 %0, i8* %20)
%22 = icmp slt i64 %21, 0
%23 = add nuw nsw i64 %19, 1
br i1 %22, label %28, label %16
24: ; preds = %16, %12
%25 = tail call i32 @write(i32 %1, i8* %5, i32 %2)
br label %26
26: ; preds = %24, %10
%27 = tail call i32 @free(i8* %5)
br label %28
28: ; preds = %18, %26
%29 = phi i32 [ 0, %26 ], [ -1, %18 ]
ret i32 %29
}