#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*/ EINVAL;
int /*<<< orphan*/ ENOENT;
int /*<<< orphan*/ cw_representation_is_valid(char const *);
int cw_representation_to_character_internal(char const *);
int /*<<< orphan*/ errno;
int cw_representation_to_character(const char *representation) {
  if (!cw_representation_is_valid(representation)) {
    errno = EINVAL;
    return 0;
  }
  int c = cw_representation_to_character_internal(representation);
  if (c) {
    return c;
  } else {
    errno = ENOENT;
    return 0;
  }
}


x86 assembly (clang, -O0):
<cw_representation_to_character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <cw_representation_is_valid@plt>
cmp    $0x0,%eax
jne    115c <cw_representation_to_character+0x3c>
mov    0x2e93(%rip),%rax
mov    (%rax),%ecx
mov    0x2e92(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    1196 <cw_representation_to_character+0x76>
mov    -0x10(%rbp),%rdi
call   1030 <cw_representation_to_character_internal@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     117d <cw_representation_to_character+0x5d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1196 <cw_representation_to_character+0x76>
mov    0x2e44(%rip),%rax
mov    (%rax),%ecx
mov    0x2e53(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cw_representation_to_character>:
push   %rbx
mov    %rdi,%rbx
call   1040 <cw_representation_is_valid@plt>
test   %eax,%eax
je     113b <cw_representation_to_character+0x1b>
mov    %rbx,%rdi
call   1030 <cw_representation_to_character_internal@plt>
test   %eax,%eax
je     1144 <cw_representation_to_character+0x24>
pop    %rbx
ret
mov    0x2e96(%rip),%rax
jmp    114b <cw_representation_to_character+0x2b>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    0x2e8c(%rip),%rcx
mov    %eax,(%rcx)
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@ENOENT = global i32 0
define i32 @cw_representation_to_character(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @cw_representation_is_valid(i8* %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = load i32, i32* @EINVAL
store i32 %9, i32* @errno
store i32 0, i32* %2
br label %19
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @cw_representation_to_character_internal(i8* %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = load i32, i32* %4
store i32 %16, i32* %2
br label %19
17: ; preds = %10
%18 = load i32, i32* @ENOENT
store i32 %18, i32* @errno
store i32 0, i32* %2
br label %19
19: ; preds = %17, %15, %8
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@ENOENT = global i32 0
define i32 @cw_representation_to_character(i8* %0) {
%2 = tail call i32 @cw_representation_is_valid(i8* %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = tail call i32 @cw_representation_to_character_internal(i8* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4, %1
%8 = phi i32* [ @EINVAL, %1 ], [ @ENOENT, %4 ]
%9 = load i32, i32* %8
store i32 %9, i32* @errno
br label %10
10: ; preds = %7, %4
%11 = phi i32 [ %5, %4 ], [ 0, %7 ]
ret i32 %11
}