#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 */
typedef int /*<<< orphan*/ pthread_key_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
char *malloc(int);
scalar_t__ pthread_getspecific(int /*<<< orphan*/);
scalar_t__ pthread_key_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ pthread_setspecific(int /*<<< orphan*/, char *);
int main(void) {
  pthread_key_t key;
  char *x, *z;
  char y;
  x = malloc(100);
  y = x[-1];
  x[1] = 'z';
  assert(0 == pthread_key_create(&key, NULL));
  assert(0 == pthread_setspecific(key, x));
  z = (char *)pthread_getspecific(key);
  assert(0 != z);
  y = z[-1];
  assert(z == x);
  assert(z[1] == 'z');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1(%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x7a,0x1(%rax)
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_key_create@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1070 <pthread_setspecific@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%edi
call   1030 <pthread_getspecific@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
mov    -0x1(%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x7a,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
movb   $0x7a,0x1(%rax)
lea    0x4(%rsp),%rdi
xor    %esi,%esi
call   1040 <pthread_key_create@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    0x4(%rsp),%edi
mov    %r14,%rsi
call   1070 <pthread_setspecific@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    0x4(%rsp),%edi
call   1030 <pthread_getspecific@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmp    %rbx,%r14
sete   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmpb   $0x7a,0x1(%rbx)
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
store i32 0, i32* %1
%6 = call i8* @malloc(i32 100)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 -1
%9 = load i8, i8* %8
store i8 %9, i8* %5
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
store i8 122, i8* %11
%12 = call i64 @pthread_key_create(i32* %2, i32* null)
%13 = icmp eq i64 0, %12
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %2
%17 = load i8*, i8** %3
%18 = call i64 @pthread_setspecific(i32 %16, i8* %17)
%19 = icmp eq i64 0, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32, i32* %2
%23 = call i64 @pthread_getspecific(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %4
%25 = load i8*, i8** %4
%26 = icmp ne i8* null, %25
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 -1
%31 = load i8, i8* %30
store i8 %31, i8* %5
%32 = load i8*, i8** %4
%33 = load i8*, i8** %3
%34 = icmp eq i8* %32, %33
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 122
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%4 = getelementptr inbounds i8, i8* %3, i64 1
store i8 122, i8* %4
%5 = call i64 @pthread_key_create(i32* %1, i32* null)
%6 = icmp eq i64 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* %1
%10 = call i64 @pthread_setspecific(i32 %9, i8* %3)
%11 = icmp eq i64 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %1
%15 = call i64 @pthread_getspecific(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = icmp ne i64 %15, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = icmp eq i8* %3, %16
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = getelementptr inbounds i8, i8* %16, i64 1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 122
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
ret i32 0
}