double fun(int a) {
  double b = 1.0;
  static double gsum = 0;
  _Thread_local static double sumloc = 5;
  _Thread_local static double bufloc;
  double *v = malloc(sizeof(*v) * 100);
#pragma omp parallel num_threads(2)
  {
    int c = 1.0;
    printf("%p %p\n", &b, &c);
  }
  free(v);
  return b + gsum + sumloc + v[0] + a + sumloc + bufloc;
}


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movabs $0x3ff0000000000000,%rax
mov    %rax,-0x10(%rbp)
mov    $0x320,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
lea    -0x10(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0x2eae(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
lea    0x2e26(%rip),%rdi
call   1050 <__tls_get_addr@plt>
movsd  -0x30(%rbp),%xmm0
movsd  0x0(%rax),%xmm1
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
addsd  %xmm2,%xmm0
cvtsi2sdl -0x4(%rbp),%xmm2
addsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    0x2deb(%rip),%rdi
call   1050 <__tls_get_addr@plt>
movsd  -0x28(%rbp),%xmm0
movsd  0x8(%rax),%xmm1
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
movabs $0x3ff0000000000000,%rax
mov    %rax,0x10(%rsp)
mov    $0x320,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movl   $0x1,0xc(%rsp)
lea    0xea5(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xorpd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  0xe6e(%rip),%xmm3
addsd  %xmm3,%xmm2
addsd  (%rbx),%xmm2
cvtsi2sd %ebp,%xmm0
addsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@fun.gsum = internal global double 0.000000e+00
@fun.sumloc = internal thread_local global double 5.000000e+00
@fun.bufloc = internal thread_local global double 0.000000e+00
@.str = [7 x i8] c"%p %p\0A\00"
define double @fun(i32 %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca double*
%5 = alloca i32
store i32 %0, i32* %2
store double 1.000000e+00, double* %3
%6 = call i8* @malloc(i64 800)
%7 = bitcast i8* %6 to double*
store double* %7, double** %4
store i32 1, i32* %5
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double* %3, i32* %5)
%9 = load double*, double** %4
%10 = bitcast double* %9 to i8*
%11 = load double, double* %3
%12 = load double, double* @fun.gsum
%13 = fadd double %11, %12
%14 = load double, double* @fun.sumloc
%15 = fadd double %13, %14
%16 = load double*, double** %4
%17 = getelementptr inbounds double, double* %16, i64 0
%18 = load double, double* %17
%19 = fadd double %15, %18
%20 = load i32, i32* %2
%21 = sitofp i32 %20 to double
%22 = fadd double %19, %21
%23 = load double, double* @fun.sumloc
%24 = fadd double %22, %23
%25 = load double, double* @fun.bufloc
%26 = fadd double %24, %25
ret double %26
}

LLVM IR (-O2):
@.str = [7 x i8] c"%p %p\0A\00"
define double @fun(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = bitcast double* %2 to i8*
store double 1.000000e+00, double* %2
%5 = tail call dereferenceable_or_null(800) i8* @malloc(i64 800)
%6 = bitcast i8* %5 to double*
%7 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), double* %2, i32* %3)
%9 = load double, double* %2
%10 = fadd double %9, 0.000000e+00
%11 = fadd double %10, 5.000000e+00
%12 = load double, double* %6
%13 = fadd double %12, %11
%14 = sitofp i32 %0 to double
%15 = fadd double %13, %14
%16 = fadd double %15, 5.000000e+00
%17 = fadd double %16, 0.000000e+00
ret double %17
}