#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__ close(int);
int getpagesize();
scalar_t__ munmap(char *, int);
int /*<<< orphan*/ perror(char *);
int exit_packetsock(int fd, char *ring) {
  if (munmap(ring, 128 * getpagesize())) {
    perror("munmap");
    return 1;
  }
  if (close(fd)) {
    perror("close");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<exit_packetsock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <getpagesize@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
shl    $0x7,%esi
call   1040 <munmap@plt>
cmp    $0x0,%rax
je     118e <exit_packetsock+0x4e>
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11bf <exit_packetsock+0x7f>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%rax
je     11b8 <exit_packetsock+0x78>
lea    0xe60(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11bf <exit_packetsock+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exit_packetsock>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r14d,%r14d
xor    %eax,%eax
call   1060 <getpagesize@plt>
shl    $0x7,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <munmap@plt>
test   %rax,%rax
jne    1179 <exit_packetsock+0x39>
mov    %ebp,%edi
call   1030 <close@plt>
test   %rax,%rax
jne    1182 <exit_packetsock+0x42>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe80(%rip),%rdi
jmp    1189 <exit_packetsock+0x49>
lea    0xe7e(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%r14d
jmp    1171 <exit_packetsock+0x31>

LLVM IR (-O0):
@.str = [7 x i8] c"munmap\00"
@.str.1 = [6 x i8] c"close\00"
define i32 @exit_packetsock(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %4
store i8* %1, i8** %5
%6 = load i8*, i8** %5
%7 = call i32 (...) @getpagesize()
%8 = mul nsw i32 128, %7
%9 = call i64 @munmap(i8* %6, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %20
13: ; preds = %2
%14 = load i32, i32* %4
%15 = call i64 @close(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %20
19: ; preds = %13
store i32 0, i32* %3
br label %20
20: ; preds = %19, %17, %11
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [7 x i8] c"munmap\00"
@.str.1 = [6 x i8] c"close\00"
define i32 @exit_packetsock(i32 %0, i8* %1) {
%3 = tail call i32 (...) @getpagesize()
%4 = shl nsw i32 %3, 7
%5 = tail call i64 @munmap(i8* %1, i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i64 @close(i32 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %7, %2
%11 = phi i8* [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %7 ]
%12 = tail call i32 @perror(i8* %11)
br label %13
13: ; preds = %10, %7
%14 = phi i32 [ 0, %7 ], [ 1, %10 ]
ret i32 %14
}