#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 errno;
int h_errno;
char *hstrerror(int);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
void logerr() {
  int errnum = errno;
  errno = 0;
  if (errnum > 0) {
    printf("Oops. \nError code: %i\nError description: %s\n", errnum,
           strerror(errnum));
  } else if (h_errno > 0) {
    printf("Oops.\nError code: %i\nError description: %s\n", h_errno,
           hstrerror(h_errno));
    h_errno = 0;
  } else {
    printf("Opps.\n There is no error data.\n");
  }
}


x86 assembly (clang, -O0):
<logerr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    0x2e8d(%rip),%rax
movl   $0x0,(%rax)
cmpl   $0x0,-0x4(%rbp)
jle    1182 <logerr+0x52>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <strerror@plt>
mov    -0x8(%rbp),%esi
mov    %rax,%rdx
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e5 <logerr+0xb5>
mov    0x2e5f(%rip),%rax
cmpl   $0x0,(%rax)
jle    11d2 <logerr+0xa2>
mov    0x2e4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1040 <hstrerror@plt>
mov    -0xc(%rbp),%esi
mov    %rax,%rdx
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e21(%rip),%rax
movl   $0x0,(%rax)
jmp    11e0 <logerr+0xb0>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e5 <logerr+0xb5>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<logerr>:
push   %r14
push   %rbx
push   %rax
mov    0x2e8d(%rip),%rax
mov    (%rax),%ebx
movl   $0x0,(%rax)
test   %ebx,%ebx
jle    1178 <logerr+0x38>
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe9b(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>
mov    0x2e69(%rip),%r14
mov    (%r14),%ebx
test   %ebx,%ebx
jle    11af <logerr+0x6f>
mov    %ebx,%edi
call   1050 <hstrerror@plt>
lea    0xe99(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xea3(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [45 x i8] c"Oops. \0AError code: %i\0AError description: %s\0A\00"
@h_errno = global i32 0
@.str.1 = [44 x i8] c"Oops.\0AError code: %i\0AError description: %s\0A\00"
@.str.2 = [32 x i8] c"Opps.\0A There is no error data.\0A\00"
define void @logerr() {
%1 = alloca i32
%2 = load i32, i32* @errno
store i32 %2, i32* %1
store i32 0, i32* @errno
%3 = load i32, i32* %1
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* %1
%7 = load i32, i32* %1
%8 = call i8* @strerror(i32 %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %6, i8* %8)
br label %21
10: ; preds = %0
%11 = load i32, i32* @h_errno
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* @h_errno
%15 = load i32, i32* @h_errno
%16 = call i8* @hstrerror(i32 %15)
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* %16)
store i32 0, i32* @h_errno
br label %20
18: ; preds = %10
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %13
br label %21
21: ; preds = %20, %5
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [45 x i8] c"Oops. \0AError code: %i\0AError description: %s\0A\00"
@h_errno = global i32 0
@.str.1 = [44 x i8] c"Oops.\0AError code: %i\0AError description: %s\0A\00"
@str = [31 x i8] c"Opps.\0A There is no error data.\00"
define void @logerr() {
%1 = load i32, i32* @errno
store i32 0, i32* @errno
%2 = icmp sgt i32 %1, 0
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i8* @strerror(i32 %1)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %4)
br label %14
6: ; preds = %0
%7 = load i32, i32* @h_errno
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i8* @hstrerror(i32 %7)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %7, i8* %10)
store i32 0, i32* @h_errno
br label %14
12: ; preds = %6
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %9, %12, %3
ret void
}