#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 CHAR_BIT;
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ sprintf(char *, char *, int);
char *str2md5(char *, scalar_t__);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, scalar_t__);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *hash(char *doorid, int n) {
  char ns[((CHAR_BIT * sizeof(int) - 1) / 3 + 2)];
  sprintf(ns, "%d", n);
  char *s = malloc(strlen(doorid) + strlen(ns) + 1);
  strncpy(s, doorid, strlen(doorid));
  strncat(s, ns, strlen(ns));
  char *ret = str2md5(s, strlen(s));
  free(s);
  return ret;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e5a(%rip),%rax
movslq (%rax),%rax
lea    -0x1(,%rax,4),%rax
ff
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mul    %rcx
mov    %rdx,%rcx
shr    %rcx
mov    %rcx,%rax
add    $0x2,%rax
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
add    $0x11,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edx
lea    0xe2b(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,-0x60(%rbp)
call   1050 <strlen@plt>
mov    -0x60(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %rax,%rdx
call   1040 <strncpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    %rax,%rdx
call   1060 <strncat@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rsi
call   1070 <str2md5@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e5b(%rip),%rax
movslq (%rax),%rax
lea    -0x1(,%rax,4),%rax
ff
movabs $0xaaaaaaaaaaaaaaab,%rcx
aa aa aa
mul    %rcx
mov    %esi,%eax
mov    %rdi,%r14
shr    %rdx
add    $0x11,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%r13
sub    %rdx,%r13
mov    %r13,%rsp
lea    0xe43(%rip),%rsi
mov    %r13,%rdi
mov    %eax,%edx
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%r15
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %rax,%r12
lea    (%r15,%rax,1),%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <strncpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1060 <strncat@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1070 <str2md5@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CHAR_BIT = global i32 0
@.str = [3 x i8] c"%d\00"
define i8* @hash(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i32, i32* @CHAR_BIT
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = sub i64 %11, 1
%13 = udiv i64 %12, 3
%14 = add i64 %13, 2
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %5
%16 = alloca i8, i64 %14
store i64 %14, i64* %6
%17 = load i32, i32* %4
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = load i8*, i8** %3
%20 = call i64 @strlen(i8* %19)
%21 = call i64 @strlen(i8* %16)
%22 = add nsw i64 %20, %21
%23 = add nsw i64 %22, 1
%24 = call i8* @malloc(i64 %23)
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = load i8*, i8** %3
%27 = load i8*, i8** %3
%28 = call i64 @strlen(i8* %27)
%29 = call i32 @strncpy(i8* %25, i8* %26, i64 %28)
%30 = load i8*, i8** %7
%31 = call i64 @strlen(i8* %16)
%32 = call i32 @strncat(i8* %30, i8* %16, i64 %31)
%33 = load i8*, i8** %7
%34 = load i8*, i8** %7
%35 = call i64 @strlen(i8* %34)
%36 = call i8* @str2md5(i8* %33, i64 %35)
store i8* %36, i8** %8
%37 = load i8*, i8** %7
%38 = call i32 @free(i8* %37)
%39 = load i8*, i8** %8
%40 = load i8*, i8** %5
ret i8* %39
}

LLVM IR (-O2):
@CHAR_BIT = global i32 0
@.str = [3 x i8] c"%d\00"
define i8* @hash(i8* %0, i32 %1) {
%3 = load i32, i32* @CHAR_BIT
%4 = sext i32 %3 to i64
%5 = shl nsw i64 %4, 2
%6 = add nsw i64 %5, -1
%7 = udiv i64 %6, 3
%8 = add nuw nsw i64 %7, 2
%9 = alloca i8, i64 %8
%10 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = call i64 @strlen(i8* %9)
%13 = add i64 %11, 1
%14 = add i64 %13, %12
%15 = tail call i8* @malloc(i64 %14)
%16 = tail call i32 @strncpy(i8* %15, i8* %0, i64 %11)
%17 = call i32 @strncat(i8* %15, i8* %9, i64 %12)
%18 = call i64 @strlen(i8* dereferenceable(1) %15)
%19 = call i8* @str2md5(i8* %15, i64 %18)
%20 = call i32 @free(i8* %15)
ret i8* %19
}