#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*/ SSL;

/* Variables and functions */
int SSL_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ printf(char *, int, char *);
int read(int, char *, int);
int ssl_or_tcp_read(SSL *ssl, int sock, char *buf, int n) {
  int p;
  if (sock) {
    p = read(sock, buf, n);
    printf("Read %d %s \n", p, buf);
  } else {
    p = SSL_read(ssl, buf, n);
  }
  return p;
}


x86 assembly (clang, -O0):
<ssl_or_tcp_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117a <ssl_or_tcp_read+0x4a>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
jmp    118d <ssl_or_tcp_read+0x5d>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <SSL_read@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_or_tcp_read>:
push   %rbp
push   %rbx
push   %rax
mov    %rdx,%rbx
test   %esi,%esi
je     1162 <ssl_or_tcp_read+0x32>
mov    %esi,%edi
mov    %rbx,%rsi
mov    %ecx,%edx
call   1050 <read@plt>
mov    %eax,%ebp
lea    0xeb1(%rip),%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1030 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rsi
mov    %ecx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <SSL_read@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Read %d %s \0A\00"
define i32 @ssl_or_tcp_read(i32* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %4
%13 = load i32, i32* %6
%14 = load i8*, i8** %7
%15 = load i32, i32* %8
%16 = call i32 @read(i32 %13, i8* %14, i32 %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = load i8*, i8** %7
%19 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %18)
br label %25
20: ; preds = %4
%21 = load i32*, i32** %5
%22 = load i8*, i8** %7
%23 = load i32, i32* %8
%24 = call i32 @SSL_read(i32* %21, i8* %22, i32 %23)
store i32 %24, i32* %9
br label %25
25: ; preds = %20, %12
%26 = load i32, i32* %9
ret i32 %26
}

LLVM IR (-O2):
@.str = [13 x i8] c"Read %d %s \0A\00"
define i32 @ssl_or_tcp_read(i32* %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp eq i32 %1, 0
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = tail call i32 @read(i32 %1, i8* %2, i32 %3)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %2)
br label %11
9: ; preds = %4
%10 = tail call i32 @SSL_read(i32* %0, i8* %2, i32 %3)
br label %11
11: ; preds = %9, %6
%12 = phi i32 [ %7, %6 ], [ %10, %9 ]
ret i32 %12
}