#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*/ printf(char *, ...);
void reassign_struct_member(void) {
  printf("-- reassign_struct_member --\n");
  struct node {
    int value;
    struct node *child;
  };
  struct node a_child = {.value = 9};
  struct node parent = {.value = 5, .child = &a_child};
  printf("Parent: %d --> %d\n", parent.value, parent.child->value);
  struct node **parent_child = &parent.child;
  struct node another_child = {.value = 40};
  *parent_child = &another_child;
  printf("Parent after child reassignment: %d --> %d\n", parent.value,
         parent.child->value);
  int *parent_value = &parent.value;
  *parent_value = 12;
  printf("Parent after value reassignment: %d --> %d\n", parent.value,
         parent.child->value);
}


x86 assembly (clang, -O0):
<reassign_struct_member>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xee1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0xf63(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xf60(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x5,-0x20(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
mov    0xf2b(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xf28(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
lea    -0x38(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movl   $0xc,(%rax)
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reassign_struct_member>:
push   %rax
lea    0xf43(%rip),%rdi
call   1030 <puts@plt>
lea    0xecc(%rip),%rdi
mov    $0x5,%esi
mov    $0x9,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xec7(%rip),%rdi
mov    $0x5,%esi
mov    $0x28,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xedb(%rip),%rdi
mov    $0xc,%esi
mov    $0x28,%edx
xor    %eax,%eax
pop    %rcx
jmp    1040 <printf@plt>

LLVM IR (-O0):
%struct.node = type { i32, %struct.node* }
@.str = [30 x i8] c"-- reassign_struct_member --\0A\00"
@__const.reassign_struct_member.a_child = %struct.node { i32 9, %struct.node* null }
@.str.1 = [19 x i8] c"Parent: %d --> %d\0A\00"
@__const.reassign_struct_member.another_child = %struct.node { i32 40, %struct.node* null }
@.str.2 = [44 x i8] c"Parent after child reassignment: %d --> %d\0A\00"
@.str.3 = [44 x i8] c"Parent after value reassignment: %d --> %d\0A\00"
define void @reassign_struct_member() {
%1 = alloca %struct.node
%2 = alloca %struct.node
%3 = alloca %struct.node**
%4 = alloca %struct.node
%5 = alloca i32*
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = bitcast %struct.node* %1 to i8*
%8 = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 0
store i32 5, i32* %8
%9 = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 1
store %struct.node* %1, %struct.node** %9
%10 = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 1
%13 = load %struct.node*, %struct.node** %12
%14 = getelementptr inbounds %struct.node, %struct.node* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %15)
%17 = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 1
store %struct.node** %17, %struct.node*** %3
%18 = bitcast %struct.node* %4 to i8*
%19 = load %struct.node**, %struct.node*** %3
store %struct.node* %4, %struct.node** %19
%20 = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 1
%23 = load %struct.node*, %struct.node** %22
%24 = getelementptr inbounds %struct.node, %struct.node* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %25)
%27 = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 0
store i32* %27, i32** %5
%28 = load i32*, i32** %5
store i32 12, i32* %28
%29 = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.node, %struct.node* %2, i32 0, i32 1
%32 = load %struct.node*, %struct.node** %31
%33 = getelementptr inbounds %struct.node, %struct.node* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 %30, i32 %34)
ret void
}

LLVM IR (-O2):
%struct.node = type { i32, %struct.node* }
@.str.1 = [19 x i8] c"Parent: %d --> %d\0A\00"
@.str.2 = [44 x i8] c"Parent after child reassignment: %d --> %d\0A\00"
@.str.3 = [44 x i8] c"Parent after value reassignment: %d --> %d\0A\00"
@str = [29 x i8] c"-- reassign_struct_member --\00"
define void @reassign_struct_member() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 9)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 40)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.3, i64 0, i64 0), i32 12, i32 40)
ret void
}