#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 */
double cos(double);
int /*<<< orphan*/ printf(char *, ...);
double sin(double);
void helloworld_c(const double *arg, double *res) {
  printf("hello, C world!\n");
  double v[10];
  size_t i;
  for (i = 0; i < 10; ++i) {
    v[i] = i;
  }
  for (i = 0; i < 10; ++i) {
    v[i] = sin(v[i]) + cos(v[i]);
  }
  res[0] = 0;
  for (i = 0; i < 10; ++i) {
    res[0] += v[i];
  }
  printf("returning %g\n", res[0]);
}


x86 assembly (clang, -O0):
<helloworld_c>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movq   $0x0,-0x68(%rbp)
cmpq   $0xa,-0x68(%rbp)
jae    11a3 <helloworld_c+0x73>
movaps 0xe98(%rip),%xmm1
movq   -0x68(%rbp),%xmm0
punpckldq %xmm1,%xmm0
movapd 0xe97(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x68(%rbp),%rax
movsd  %xmm0,-0x60(%rbp,%rax,8)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    1156 <helloworld_c+0x26>
movq   $0x0,-0x68(%rbp)
cmpq   $0xa,-0x68(%rbp)
jae    1200 <helloworld_c+0xd0>
mov    -0x68(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm0
call   1040 <sin@plt>
movsd  %xmm0,-0x70(%rbp)
mov    -0x68(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm0
call   1050 <cos@plt>
movaps %xmm0,%xmm1
movsd  -0x70(%rbp),%xmm0
addsd  %xmm1,%xmm0
mov    -0x68(%rbp),%rax
movsd  %xmm0,-0x60(%rbp,%rax,8)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    11ab <helloworld_c+0x7b>
mov    -0x10(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movq   $0x0,-0x68(%rbp)
cmpq   $0xa,-0x68(%rbp)
jae    1245 <helloworld_c+0x115>
mov    -0x68(%rbp),%rax
movsd  -0x60(%rbp,%rax,8),%xmm0
mov    -0x10(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x68(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
jmp    1213 <helloworld_c+0xe3>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
lea    0xddd(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<helloworld_c>:
push   %rbx
mov    %rsi,%rbx
lea    0xeeb(%rip),%rdi
call   1030 <puts@plt>
movabs $0x400303c128a0692d,%rax
03 03 40
mov    %rax,(%rbx)
lea    0xec4(%rip),%rdi
movsd  0xeb4(%rip),%xmm0
mov    $0x1,%al
pop    %rbx
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"hello, C world!\0A\00"
@.str.1 = [14 x i8] c"returning %g\0A\00"
define void @helloworld_c(double* %0, double* %1) {
%3 = alloca double*
%4 = alloca double*
%5 = alloca [10 x double]
%6 = alloca i64
store double* %0, double** %3
store double* %1, double** %4
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %6
br label %8
8: ; preds = %16, %2
%9 = load i64, i64* %6
%10 = icmp ult i64 %9, 10
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i64, i64* %6
%13 = uitofp i64 %12 to double
%14 = load i64, i64* %6
%15 = getelementptr inbounds [10 x double], [10 x double]* %5, i64 0, i64 %14
store double %13, double* %15
br label %16
16: ; preds = %11
%17 = load i64, i64* %6
%18 = add i64 %17, 1
store i64 %18, i64* %6
br label %8
19: ; preds = %8
store i64 0, i64* %6
br label %20
20: ; preds = %35, %19
%21 = load i64, i64* %6
%22 = icmp ult i64 %21, 10
br i1 %22, label %23, label %38
23: ; preds = %20
%24 = load i64, i64* %6
%25 = getelementptr inbounds [10 x double], [10 x double]* %5, i64 0, i64 %24
%26 = load double, double* %25
%27 = call double @sin(double %26)
%28 = load i64, i64* %6
%29 = getelementptr inbounds [10 x double], [10 x double]* %5, i64 0, i64 %28
%30 = load double, double* %29
%31 = call double @cos(double %30)
%32 = fadd double %27, %31
%33 = load i64, i64* %6
%34 = getelementptr inbounds [10 x double], [10 x double]* %5, i64 0, i64 %33
store double %32, double* %34
br label %35
35: ; preds = %23
%36 = load i64, i64* %6
%37 = add i64 %36, 1
store i64 %37, i64* %6
br label %20
38: ; preds = %20
%39 = load double*, double** %4
%40 = getelementptr inbounds double, double* %39, i64 0
store double 0.000000e+00, double* %40
store i64 0, i64* %6
br label %41
41: ; preds = %52, %38
%42 = load i64, i64* %6
%43 = icmp ult i64 %42, 10
br i1 %43, label %44, label %55
44: ; preds = %41
%45 = load i64, i64* %6
%46 = getelementptr inbounds [10 x double], [10 x double]* %5, i64 0, i64 %45
%47 = load double, double* %46
%48 = load double*, double** %4
%49 = getelementptr inbounds double, double* %48, i64 0
%50 = load double, double* %49
%51 = fadd double %50, %47
store double %51, double* %49
br label %52
52: ; preds = %44
%53 = load i64, i64* %6
%54 = add i64 %53, 1
store i64 %54, i64* %6
br label %41
55: ; preds = %41
%56 = load double*, double** %4
%57 = getelementptr inbounds double, double* %56, i64 0
%58 = load double, double* %57
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %58)
ret void
}

LLVM IR (-O2):
@.str.1 = [14 x i8] c"returning %g\0A\00"
@str = [16 x i8] c"hello, C world!\00"
define void @helloworld_c(double* nocapture readnone %0, double* nocapture %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
store double 0x400303C128A0692D, double* %1
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double 0x400303C128A0692D)
ret void
}