#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 */
typedef struct TYPE_4__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ wchar_t;
struct TYPE_4__ {
  char *key;
  int /*<<< orphan*/ *data;
};
typedef TYPE_1__ ENTRY;

/* Variables and functions */
int /*<<< orphan*/ ENTER;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ FIND;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
TYPE_1__ *hsearch(TYPE_1__, int /*<<< orphan*/);
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int wc_to_key(int /*<<< orphan*/, char *, size_t);
void update_frequencies(wchar_t wc) {
  char *key;
  size_t keysz;
  int err, data;
  ENTRY entry, *pentry;
  keysz = sizeof(wchar_t) + 1;
  key = malloc(keysz);
  if (!key) {
    perror("malloc failed");
    exit(EXIT_FAILURE);
  }
  err = wc_to_key(wc, key, keysz);
  if (err) {
    fprintf(stderr, "FATAL: wc_to_key failed\n");
    exit(EXIT_FAILURE);
  }
  entry.key = key;
  entry.data = NULL;
  pentry = hsearch(entry, FIND);
  if (!pentry)
    pentry = &entry;
  else
    free(entry.key);
  data = (int)(long)pentry->data + 1;
  pentry->data = (void *)(long)data;
  hsearch(*pentry, ENTER);
}


x86 assembly (clang, -O0):
<update_frequencies>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x5,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b5 <update_frequencies+0x45>
lea    0xe5e(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <wc_to_key@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     11f5 <update_frequencies+0x85>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%edx
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <hsearch@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1237 <update_frequencies+0xc7>
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1240 <update_frequencies+0xd0>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x38(%rbp),%rax
mov    0x2d83(%rip),%rcx
mov    (%rcx),%edx
mov    (%rax),%rdi
mov    0x8(%rax),%rsi
call   1060 <hsearch@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_frequencies>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
mov    $0x5,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11fe <update_frequencies+0x8e>
mov    %rax,%rbx
mov    $0x5,%edx
mov    %ebp,%edi
mov    %rax,%rsi
call   1040 <wc_to_key@plt>
test   %eax,%eax
jne    120c <update_frequencies+0x9c>
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <hsearch@plt>
test   %rax,%rax
je     11d8 <update_frequencies+0x68>
mov    %rax,%rbp
mov    %rax,%r14
add    $0x8,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rbp),%eax
mov    0x0(%rbp),%rbx
add    $0x1,%eax
movslq %eax,%rsi
jmp    11e2 <update_frequencies+0x72>
lea    0x8(%rsp),%r14
mov    $0x1,%esi
mov    %rsi,(%r14)
mov    0x2dfc(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <hsearch@plt>
lea    0xdfb(%rip),%rdi
call   1080 <perror@plt>
jmp    1221 <update_frequencies+0xb1>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_4__ = type { i8*, i32* }
@.str = [14 x i8] c"malloc failed\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"FATAL: wc_to_key failed\0A\00"
@FIND = global i32 0
@ENTER = global i32 0
define void @update_frequencies(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.TYPE_4__
%8 = alloca %struct.TYPE_4__*
store i32 %0, i32* %2
store i64 5, i64* %4
%9 = load i64, i64* %4
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
%18 = load i32, i32* %2
%19 = load i8*, i8** %3
%20 = load i64, i64* %4
%21 = call i32 @wc_to_key(i32 %18, i8* %19, i64 %20)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %17
%30 = load i8*, i8** %3
%31 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
store i8* %30, i8** %31
%32 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 1
store i32* null, i32** %32
%33 = load i32, i32* @FIND
%34 = bitcast %struct.TYPE_4__* %7 to { i8*, i32* }*
%35 = getelementptr inbounds { i8*, i32* }, { i8*, i32* }* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = getelementptr inbounds { i8*, i32* }, { i8*, i32* }* %34, i32 0, i32 1
%38 = load i32*, i32** %37
%39 = call %struct.TYPE_4__* @hsearch(i8* %36, i32* %38, i32 %33)
store %struct.TYPE_4__* %39, %struct.TYPE_4__** %8
%40 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%41 = icmp ne %struct.TYPE_4__* %40, null
br i1 %41, label %43, label %42
42: ; preds = %29
store %struct.TYPE_4__* %7, %struct.TYPE_4__** %8
br label %47
43: ; preds = %29
%44 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %7, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = call i32 @free(i8* %45)
br label %47
47: ; preds = %43, %42
%48 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%49 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %48, i32 0, i32 1
%50 = load i32*, i32** %49
%51 = ptrtoint i32* %50 to i64
%52 = trunc i64 %51 to i32
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = inttoptr i64 %55 to i8*
%57 = bitcast i8* %56 to i32*
%58 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%59 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %58, i32 0, i32 1
store i32* %57, i32** %59
%60 = load %struct.TYPE_4__*, %struct.TYPE_4__** %8
%61 = load i32, i32* @ENTER
%62 = bitcast %struct.TYPE_4__* %60 to { i8*, i32* }*
%63 = getelementptr inbounds { i8*, i32* }, { i8*, i32* }* %62, i32 0, i32 0
%64 = load i8*, i8** %63
%65 = getelementptr inbounds { i8*, i32* }, { i8*, i32* }* %62, i32 0, i32 1
%66 = load i32*, i32** %65
%67 = call %struct.TYPE_4__* @hsearch(i8* %64, i32* %66, i32 %61)
ret void
}

LLVM IR (-O2):
%struct.TYPE_4__ = type { i8*, i32* }
@.str = [14 x i8] c"malloc failed\00"
@EXIT_FAILURE = global i32 0
@stderr = global i32 0
@.str.1 = [25 x i8] c"FATAL: wc_to_key failed\0A\00"
@FIND = global i32 0
@ENTER = global i32 0
define void @update_frequencies(i32 %0) {
%2 = alloca i32*
%3 = bitcast i32** %2 to i8*
%4 = tail call dereferenceable_or_null(5) i8* @malloc(i64 5)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = tail call i32 @wc_to_key(i32 %0, i8* %4, i64 5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %10
%19 = load i32, i32* @FIND
%20 = tail call %struct.TYPE_4__* @hsearch(i8* %4, i32* null, i32 %19)
%21 = icmp eq %struct.TYPE_4__* %20, null
br i1 %21, label %33, label %22
22: ; preds = %18
%23 = getelementptr %struct.TYPE_4__, %struct.TYPE_4__* %20, i64 0, i32 0
%24 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %20, i64 0, i32 1
%25 = tail call i32 @free(i8* %4)
%26 = load i32*, i32** %24
%27 = load i8*, i8** %23
%28 = ptrtoint i32* %26 to i64
%29 = shl i64 %28, 32
%30 = add i64 %29, 4294967296
%31 = ashr exact i64 %30, 32
%32 = inttoptr i64 %31 to i32*
br label %33
33: ; preds = %18, %22
%34 = phi i8* [ %27, %22 ], [ %4, %18 ]
%35 = phi i32* [ %32, %22 ], [ inttoptr (i64 1 to i32*), %18 ]
%36 = phi i32** [ %24, %22 ], [ %2, %18 ]
store i32* %35, i32** %36
%37 = load i32, i32* @ENTER
%38 = tail call %struct.TYPE_4__* @hsearch(i8* %34, i32* %35, i32 %37)
ret void
}