#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 */
struct metasurface {
  int dummy;
};

/* Variables and functions */
float eval(struct metasurface *, float, float, float);
int /*<<< orphan*/ glNormal3f(float, float, float);
int /*<<< orphan*/ glVertex3f(float, float, float);
void vertex(struct metasurface *ms, float x, float y, float z) {
  static const float delta = 0.01;
  float val = eval(ms, x, y, z);
  float dfdx = eval(ms, x + delta, y, z) - val;
  float dfdy = eval(ms, x, y + delta, z) - val;
  float dfdz = eval(ms, x, y, z + delta) - val;
  glNormal3f(dfdx, dfdy, dfdz);
  glVertex3f(x, y, z);
}


x86 assembly (clang, -O0):
<vertex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
movss  %xmm1,-0x10(%rbp)
movss  %xmm2,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
movss  -0x14(%rbp),%xmm2
call   1040 <eval@plt>
movss  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movss  0xe8c(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
movss  -0x14(%rbp),%xmm2
call   1040 <eval@plt>
subss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
movss  0xe5d(%rip),%xmm1
addss  -0x10(%rbp),%xmm1
movss  -0x14(%rbp),%xmm2
call   1040 <eval@plt>
subss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
movss  0xe2e(%rip),%xmm2
addss  -0x14(%rbp),%xmm2
call   1040 <eval@plt>
subss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x24(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  -0x20(%rbp),%xmm1
movss  -0x24(%rbp),%xmm2
call   1050 <glNormal3f@plt>
movss  -0xc(%rbp),%xmm0
movss  -0x10(%rbp),%xmm1
movss  -0x14(%rbp),%xmm2
call   1030 <glVertex3f@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vertex>:
push   %rbx
sub    $0x20,%rsp
movss  %xmm2,0x10(%rsp)
movss  %xmm1,0xc(%rsp)
movss  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
call   1040 <eval@plt>
movss  %xmm0,0x14(%rsp)
movss  0x8(%rsp),%xmm0
addss  0xe9d(%rip),%xmm0
mov    %rbx,%rdi
movss  0xc(%rsp),%xmm1
movss  0x10(%rsp),%xmm2
call   1040 <eval@plt>
subss  0x14(%rsp),%xmm0
movss  %xmm0,0x1c(%rsp)
movss  0xc(%rsp),%xmm1
addss  0xe6f(%rip),%xmm1
mov    %rbx,%rdi
movss  0x8(%rsp),%xmm0
movss  0x10(%rsp),%xmm2
call   1040 <eval@plt>
subss  0x14(%rsp),%xmm0
movss  %xmm0,0x18(%rsp)
movss  0xe47(%rip),%xmm2
addss  0x10(%rsp),%xmm2
mov    %rbx,%rdi
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
call   1040 <eval@plt>
movaps %xmm0,%xmm2
subss  0x14(%rsp),%xmm2
movss  0x1c(%rsp),%xmm0
movss  0x18(%rsp),%xmm1
call   1050 <glNormal3f@plt>
movss  0x8(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
movss  0x10(%rsp),%xmm2
add    $0x20,%rsp
pop    %rbx
jmp    1030 <glVertex3f@plt>

LLVM IR (-O0):
%struct.metasurface = type { i32 }
@vertex.delta = internal constant float 0x3F847AE140000000
define void @vertex(%struct.metasurface* %0, float %1, float %2, float %3) {
%5 = alloca %struct.metasurface*
%6 = alloca float
%7 = alloca float
%8 = alloca float
%9 = alloca float
%10 = alloca float
%11 = alloca float
%12 = alloca float
store %struct.metasurface* %0, %struct.metasurface** %5
store float %1, float* %6
store float %2, float* %7
store float %3, float* %8
%13 = load %struct.metasurface*, %struct.metasurface** %5
%14 = load float, float* %6
%15 = load float, float* %7
%16 = load float, float* %8
%17 = call float @eval(%struct.metasurface* %13, float %14, float %15, float %16)
store float %17, float* %9
%18 = load %struct.metasurface*, %struct.metasurface** %5
%19 = load float, float* %6
%20 = fadd float %19, 0x3F847AE140000000
%21 = load float, float* %7
%22 = load float, float* %8
%23 = call float @eval(%struct.metasurface* %18, float %20, float %21, float %22)
%24 = load float, float* %9
%25 = fsub float %23, %24
store float %25, float* %10
%26 = load %struct.metasurface*, %struct.metasurface** %5
%27 = load float, float* %6
%28 = load float, float* %7
%29 = fadd float %28, 0x3F847AE140000000
%30 = load float, float* %8
%31 = call float @eval(%struct.metasurface* %26, float %27, float %29, float %30)
%32 = load float, float* %9
%33 = fsub float %31, %32
store float %33, float* %11
%34 = load %struct.metasurface*, %struct.metasurface** %5
%35 = load float, float* %6
%36 = load float, float* %7
%37 = load float, float* %8
%38 = fadd float %37, 0x3F847AE140000000
%39 = call float @eval(%struct.metasurface* %34, float %35, float %36, float %38)
%40 = load float, float* %9
%41 = fsub float %39, %40
store float %41, float* %12
%42 = load float, float* %10
%43 = load float, float* %11
%44 = load float, float* %12
%45 = call i32 @glNormal3f(float %42, float %43, float %44)
%46 = load float, float* %6
%47 = load float, float* %7
%48 = load float, float* %8
%49 = call i32 @glVertex3f(float %46, float %47, float %48)
ret void
}

LLVM IR (-O2):
%struct.metasurface = type { i32 }
define void @vertex(%struct.metasurface* %0, float %1, float %2, float %3) {
%5 = tail call float @eval(%struct.metasurface* %0, float %1, float %2, float %3)
%6 = fadd float %1, 0x3F847AE140000000
%7 = tail call float @eval(%struct.metasurface* %0, float %6, float %2, float %3)
%8 = fsub float %7, %5
%9 = fadd float %2, 0x3F847AE140000000
%10 = tail call float @eval(%struct.metasurface* %0, float %1, float %9, float %3)
%11 = fsub float %10, %5
%12 = fadd float %3, 0x3F847AE140000000
%13 = tail call float @eval(%struct.metasurface* %0, float %1, float %2, float %12)
%14 = fsub float %13, %5
%15 = tail call i32 @glNormal3f(float %8, float %11, float %14)
%16 = tail call i32 @glVertex3f(float %1, float %2, float %3)
ret void
}