#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 */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ print(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void check_socket(int rc, const char *fn) {
  if (rc > 0)
    return;
  else if (!rc) {
    print(LOG_ERR, "error: connection was closed by server\n");
    exit(1);
  }
  print(LOG_ERR, "error: %s failed. %s\n", fn, strerror(errno));
  exit(1);
}


x86 assembly (clang, -O0):
<check_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    114f <check_socket+0x1f>
add    $0x20,%rsp
pop    %rbp
ret
cmpl   $0x0,-0x4(%rbp)
jne    117a <check_socket+0x4a>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1030 <print@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
jmp    117f <check_socket+0x4f>
mov    0x2e4a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    %eax,%ecx
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1030 <print@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<check_socket>:
push   %rbp
push   %rbx
push   %rax
test   %edi,%edi
jle    113e <check_socket+0xe>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e8b(%rip),%rax
mov    (%rax),%ebp
jne    1163 <check_socket+0x33>
lea    0xeb0(%rip),%rsi
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <print@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    %rsi,%rbx
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xead(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <print@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [40 x i8] c"error: connection was closed by server\0A\00"
@.str.1 = [22 x i8] c"error: %s failed. %s\0A\00"
@errno = global i32 0
define void @check_socket(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%5 = load i32, i32* %3
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %2
ret void
8: ; preds = %2
%9 = load i32, i32* %3
%10 = icmp ne i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @LOG_ERR
%13 = call i32 (i32, i8*, ...) @print(i32 %12, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %8
br label %16
16: ; preds = %15
%17 = load i32, i32* @LOG_ERR
%18 = load i8*, i8** %4
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = call i32 (i32, i8*, ...) @print(i32 %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %20)
%22 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [40 x i8] c"error: connection was closed by server\0A\00"
@.str.1 = [22 x i8] c"error: %s failed. %s\0A\00"
@errno = global i32 0
define void @check_socket(i32 %0, i8* %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %5
4: ; preds = %2
ret void
5: ; preds = %2
%6 = icmp eq i32 %0, 0
%7 = load i32, i32* @LOG_ERR
br i1 %6, label %8, label %11
8: ; preds = %5
%9 = tail call i32 (i32, i8*, ...) @print(i32 %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5
%12 = load i32, i32* @errno
%13 = tail call i32 @strerror(i32 %12)
%14 = tail call i32 (i32, i8*, ...) @print(i32 %7, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %13)
%15 = tail call i32 @exit(i32 1)
unreachable
}