#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 /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, double);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
void *sumador(void *p) {
  double x = 1.0, l;
  extern double contador;
  int *id, i;
  id = (int *)p;
  for (i = 0; i < 1000; i++) {
    l = contador;
    fprintf(stdout, "Hilo %d: %f\n", *id, contador);
    l += x;
    contador = l;
  }
  pthread_exit(NULL);
}


x86 assembly (clang, -O0):
<sumador>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movsd  0xecc(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3e8,-0x2c(%rbp)
jge    11b8 <sumador+0x98>
mov    0x2e7c(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
mov    0x2e5d(%rip),%rax
movsd  (%rax),%xmm0
lea    0xe82(%rip),%rsi
call   1030 <fprintf@plt>
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
mov    0x2e32(%rip),%rax
movsd  %xmm0,(%rax)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1148 <sumador+0x28>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sumador>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2ea2(%rip),%r15
movsd  (%r15),%xmm0
mov    $0x3e8,%ebp
mov    0x2e99(%rip),%r12
lea    0xeba(%rip),%r14
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
mov    (%r12),%edi
mov    (%rbx),%edx
mov    %r14,%rsi
movsd  0x8(%rsp),%xmm0
call   1030 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0xe88(%rip),%xmm0
movsd  %xmm0,(%r15)
add    $0xffffffff,%ebp
jne    1150 <sumador+0x30>
xor    %edi,%edi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <pthread_exit@plt>

LLVM IR (-O0):
@contador = external global double
@stdout = global i32 0
@.str = [13 x i8] c"Hilo %d: %f\0A\00"
define i8* @sumador(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca double
%5 = alloca double
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %3
store double 1.000000e+00, double* %4
%8 = load i8*, i8** %3
%9 = bitcast i8* %8 to i32*
store i32* %9, i32** %6
store i32 0, i32* %7
br label %10
10: ; preds = %24, %1
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 1000
br i1 %12, label %13, label %27
13: ; preds = %10
%14 = load double, double* @contador
store double %14, double* %5
%15 = load i32, i32* @stdout
%16 = load i32*, i32** %6
%17 = load i32, i32* %16
%18 = load double, double* @contador
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %17, double %18)
%20 = load double, double* %4
%21 = load double, double* %5
%22 = fadd double %21, %20
store double %22, double* %5
%23 = load double, double* %5
store double %23, double* @contador
br label %24
24: ; preds = %13
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %10
27: ; preds = %10
%28 = call i32 @pthread_exit(i32* null)
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
@contador = external global double
@stdout = global i32 0
@.str = [13 x i8] c"Hilo %d: %f\0A\00"
define noalias i8* @sumador(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load double, double* @contador
br label %4
4: ; preds = %1, %4
%5 = phi double [ %3, %1 ], [ %10, %4 ]
%6 = phi i32 [ 0, %1 ], [ %11, %4 ]
%7 = load i32, i32* @stdout
%8 = load i32, i32* %2
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8, double %5)
%10 = fadd double %5, 1.000000e+00
store double %10, double* @contador
%11 = add nuw nsw i32 %6, 1
%12 = icmp eq i32 %11, 1000
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = tail call i32 @pthread_exit(i32* null)
ret i8* undef
}