#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 Z_DATA_ERROR 132
#define Z_ERRNO 131
#define Z_MEM_ERROR 130
#define Z_STREAM_ERROR 129
#define Z_VERSION_ERROR 128
char *malloc(size_t);
size_t snprintf(char *, size_t, char *, int);
const char *zlib_errstr(int ret) {
  switch (ret) {
  case Z_ERRNO:
    return "Z_ERRNO";
  case Z_STREAM_ERROR:
    return "invalid compression level";
  case Z_DATA_ERROR:
    return "invalid or incomplete deflate data";
  case Z_MEM_ERROR:
    return "out of memory";
  case Z_VERSION_ERROR:
    return "zlib version mismatch!";
  default: {
    size_t len = snprintf(NULL, 0, "unk zlib error %i", ret);
    char *buf = malloc(len + 1);
    snprintf(buf, len + 1, "unk zlib error %i", ret);
    return buf;
  }
  }
}


x86 assembly (clang, -O0):
<zlib_errstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x4,%eax
ja     11a4 <zlib_errstr+0x84>
mov    -0x28(%rbp),%rax
lea    0xeb5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeb9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f2 <zlib_errstr+0xd2>
lea    0xeb1(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f2 <zlib_errstr+0xd2>
lea    0xebb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f2 <zlib_errstr+0xd2>
lea    0xece(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f2 <zlib_errstr+0xd2>
lea    0xecc(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11f2 <zlib_errstr+0xd2>
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%esi
lea    0xecc(%rip),%rdx
mov    %rsi,%rdi
call   1030 <snprintf@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
add    $0x1,%rsi
mov    -0xc(%rbp),%ecx
lea    0xe99(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zlib_errstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    -0x80(%r14),%eax
cmp    $0x5,%eax
jae    1146 <zlib_errstr+0x26>
cltq
lea    0xf3f(%rip),%rcx
movslq (%rcx,%rax,4),%rbx
add    %rcx,%rbx
jmp    117c <zlib_errstr+0x5c>
lea    0xf1d(%rip),%r15
xor    %edi,%edi
xor    %esi,%esi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <snprintf@plt>
lea    0x1(%rax),%r12
mov    %r12,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"Z_ERRNO\00"
@.str.1 = [26 x i8] c"invalid compression level\00"
@.str.2 = [35 x i8] c"invalid or incomplete deflate data\00"
@.str.3 = [14 x i8] c"out of memory\00"
@.str.4 = [23 x i8] c"zlib version mismatch!\00"
@.str.5 = [18 x i8] c"unk zlib error %i\00"
define i8* @zlib_errstr(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i64
%5 = alloca i8*
store i32 %0, i32* %3
%6 = load i32, i32* %3
switch i32 %6, label %12 [
i32 131, label %7
i32 129, label %8
i32 132, label %9
i32 130, label %10
i32 128, label %11
]
7: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2
br label %24
8: ; preds = %1
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %24
9: ; preds = %1
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %24
10: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %24
11: ; preds = %1
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %24
12: ; preds = %1
%13 = load i32, i32* %3
%14 = call i64 @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %13)
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = add i64 %15, 1
%17 = call i8* @malloc(i64 %16)
store i8* %17, i8** %5
%18 = load i8*, i8** %5
%19 = load i64, i64* %4
%20 = add i64 %19, 1
%21 = load i32, i32* %3
%22 = call i64 @snprintf(i8* %18, i64 %20, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = load i8*, i8** %5
store i8* %23, i8** %2
br label %24
24: ; preds = %12, %11, %10, %9, %8, %7
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [8 x i8] c"Z_ERRNO\00"
@.str.1 = [26 x i8] c"invalid compression level\00"
@.str.2 = [35 x i8] c"invalid or incomplete deflate data\00"
@.str.3 = [14 x i8] c"out of memory\00"
@.str.4 = [23 x i8] c"zlib version mismatch!\00"
@.str.5 = [18 x i8] c"unk zlib error %i\00"
@reltable.zlib_errstr = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.zlib_errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([26 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.zlib_errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.zlib_errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.zlib_errstr to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([35 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.zlib_errstr to i64)) to i32)]
define i8* @zlib_errstr(i32 %0) {
%2 = add i32 %0, -128
%3 = icmp ult i32 %2, 5
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = tail call i64 @snprintf(i8* null, i64 0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %0)
%6 = add i64 %5, 1
%7 = tail call i8* @malloc(i64 %6)
%8 = tail call i64 @snprintf(i8* %7, i64 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 %0)
br label %13
9: ; preds = %1
%10 = sext i32 %2 to i64
%11 = shl i64 %10, 2
%12 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.zlib_errstr to i8*), i64 %11)
br label %13
13: ; preds = %9, %4
%14 = phi i8* [ %7, %4 ], [ %12, %9 ]
ret i8* %14
}