#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 */
#define EBADF 130
#define EINTR 129
#define EIO 128
int close(int);
int errno;
int /*<<< orphan*/ perror(char *);
bool printer_disconnect(int socket_descriptor) {
  int error_code;
  error_code = close(socket_descriptor);
  if (error_code == -1) {
    switch (errno) {
    case EBADF:
      perror("Socket descriptor given was not valid.");
      break;
    case EINTR:
      perror("Closing socket descriptor was interrupted by a signal.");
      break;
    case EIO:
      perror("I/O error occurred during closing of socket descriptor.");
      break;
    }
  }
  if (error_code) {
    return false;
  } else {
    return true;
  }
}


x86 assembly (clang, -O0):
<printer_disconnect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11b5 <printer_disconnect+0x95>
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
sub    $0x80,%eax
je     11a4 <printer_disconnect+0x84>
jmp    115c <printer_disconnect+0x3c>
mov    -0x10(%rbp),%eax
sub    $0x81,%eax
je     1193 <printer_disconnect+0x73>
jmp    116f <printer_disconnect+0x4f>
mov    -0x10(%rbp),%eax
sub    $0x82,%eax
jne    11b0 <printer_disconnect+0x90>
jmp    1182 <printer_disconnect+0x62>
lea    0xe77(%rip),%rdi
call   1040 <perror@plt>
jmp    11b0 <printer_disconnect+0x90>
lea    0xe8d(%rip),%rdi
call   1040 <perror@plt>
jmp    11b0 <printer_disconnect+0x90>
lea    0xeb3(%rip),%rdi
call   1040 <perror@plt>
jmp    11b5 <printer_disconnect+0x95>
cmpl   $0x0,-0xc(%rbp)
je     11cb <printer_disconnect+0xab>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <printer_disconnect+0xb2>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printer_disconnect>:
push   %rbx
call   1030 <close@plt>
test   %eax,%eax
je     115d <printer_disconnect+0x3d>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
jne    1162 <printer_disconnect+0x42>
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
cmp    $0x80,%eax
je     1166 <printer_disconnect+0x46>
cmp    $0x81,%eax
je     1174 <printer_disconnect+0x54>
cmp    $0x82,%eax
jne    1162 <printer_disconnect+0x42>
lea    0xeaa(%rip),%rdi
call   1040 <perror@plt>
jmp    1162 <printer_disconnect+0x42>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
ret
lea    0xef1(%rip),%rdi
call   1040 <perror@plt>
jmp    1162 <printer_disconnect+0x42>
lea    0xeac(%rip),%rdi
call   1040 <perror@plt>
jmp    1162 <printer_disconnect+0x42>

LLVM IR (-O0):
@errno = global i32 0
@.str = [39 x i8] c"Socket descriptor given was not valid.\00"
@.str.1 = [55 x i8] c"Closing socket descriptor was interrupted by a signal.\00"
@.str.2 = [56 x i8] c"I/O error occurred during closing of socket descriptor.\00"
define i32 @printer_disconnect(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i32 @close(i32 %5)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %18
9: ; preds = %1
%10 = load i32, i32* @errno
switch i32 %10, label %17 [
i32 130, label %11
i32 129, label %13
i32 128, label %15
]
11: ; preds = %9
%12 = call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %17
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
br label %17
15: ; preds = %9
%16 = call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %9, %15, %13, %11
br label %18
18: ; preds = %17, %1
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 0, i32* %2
br label %23
22: ; preds = %18
store i32 1, i32* %2
br label %23
23: ; preds = %22, %21
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [39 x i8] c"Socket descriptor given was not valid.\00"
@.str.1 = [55 x i8] c"Closing socket descriptor was interrupted by a signal.\00"
@.str.2 = [56 x i8] c"I/O error occurred during closing of socket descriptor.\00"
define i32 @printer_disconnect(i32 %0) {
%2 = tail call i32 @close(i32 %0)
switch i32 %2, label %12 [
i32 -1, label %3
i32 0, label %11
]
3: ; preds = %1
%4 = load i32, i32* @errno
switch i32 %4, label %12 [
i32 130, label %5
i32 129, label %7
i32 128, label %9
]
5: ; preds = %3
%6 = tail call i32 @perror(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %12
7: ; preds = %3
%8 = tail call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0))
br label %12
9: ; preds = %3
%10 = tail call i32 @perror(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.2, i64 0, i64 0))
br label %12
11: ; preds = %1
br label %12
12: ; preds = %3, %9, %7, %5, %1, %11
%13 = phi i32 [ 1, %11 ], [ 0, %1 ], [ 0, %5 ], [ 0, %7 ], [ 0, %9 ], [ 0, %3 ]
ret i32 %13
}