#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 pig {
  int dummy;
};
typedef struct pig dog;
typedef struct pig animal;

/* Variables and functions */
char *animal_get_name(struct pig *);
int /*<<< orphan*/ animal_shout(struct pig *, int);
struct pig *init_dog();
struct pig *init_pig();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  struct animal *anim = NULL;
  struct pig *pig = NULL;
  struct dog *dog = NULL;
  pig = init_pig();
  printf("name=%s\n", animal_get_name(pig));
  printf("------------------------------------\n");
  dog = init_dog();
  printf("name=%s\n", animal_get_name(dog));
  printf("------------------------------------\n");
  anim = (struct animal *)pig;
  printf("name=%s\n", animal_get_name(anim));
  animal_shout(anim, 20);
  printf("------------------------------------\n");
  anim = (struct animal *)dog;
  printf("name=%s\n", animal_get_name(anim));
  animal_shout(anim, 100);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1040 <init_pig@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <animal_get_name@plt>
mov    %rax,%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <init_dog@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <animal_get_name@plt>
mov    %rax,%rsi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <animal_get_name@plt>
mov    %rax,%rsi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x14,%esi
call   1050 <animal_shout@plt>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <animal_get_name@plt>
mov    %rax,%rsi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x64,%esi
call   1050 <animal_shout@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1050 <init_pig@plt>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <animal_get_name@plt>
lea    0xe7f(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe74(%rip),%r12
mov    %r12,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <init_dog@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <animal_get_name@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1080 <animal_get_name@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
mov    $0x14,%esi
call   1060 <animal_shout@plt>
mov    %r12,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1080 <animal_get_name@plt>
mov    %r14,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <animal_shout@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.animal = type opaque
%struct.pig = type { i32 }
%struct.dog = type opaque
@.str = [9 x i8] c"name=%s\0A\00"
@.str.1 = [38 x i8] c"------------------------------------\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.animal*
%3 = alloca %struct.pig*
%4 = alloca %struct.dog*
store i32 0, i32* %1
store %struct.animal* null, %struct.animal** %2
store %struct.pig* null, %struct.pig** %3
store %struct.dog* null, %struct.dog** %4
%5 = call %struct.pig* (...) @init_pig()
store %struct.pig* %5, %struct.pig** %3
%6 = load %struct.pig*, %struct.pig** %3
%7 = call i8* @animal_get_name(%struct.pig* %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%10 = call %struct.pig* (...) @init_dog()
%11 = bitcast %struct.pig* %10 to %struct.dog*
store %struct.dog* %11, %struct.dog** %4
%12 = load %struct.dog*, %struct.dog** %4
%13 = bitcast %struct.dog* %12 to %struct.pig*
%14 = call i8* @animal_get_name(%struct.pig* %13)
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%17 = load %struct.pig*, %struct.pig** %3
%18 = bitcast %struct.pig* %17 to %struct.animal*
store %struct.animal* %18, %struct.animal** %2
%19 = load %struct.animal*, %struct.animal** %2
%20 = bitcast %struct.animal* %19 to %struct.pig*
%21 = call i8* @animal_get_name(%struct.pig* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = load %struct.animal*, %struct.animal** %2
%24 = bitcast %struct.animal* %23 to %struct.pig*
%25 = call i32 @animal_shout(%struct.pig* %24, i32 20)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%27 = load %struct.dog*, %struct.dog** %4
%28 = bitcast %struct.dog* %27 to %struct.animal*
store %struct.animal* %28, %struct.animal** %2
%29 = load %struct.animal*, %struct.animal** %2
%30 = bitcast %struct.animal* %29 to %struct.pig*
%31 = call i8* @animal_get_name(%struct.pig* %30)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = load %struct.animal*, %struct.animal** %2
%34 = bitcast %struct.animal* %33 to %struct.pig*
%35 = call i32 @animal_shout(%struct.pig* %34, i32 100)
ret i32 0
}

LLVM IR (-O2):
%struct.animal = type opaque
%struct.pig = type { i32 }
%struct.dog = type opaque
@.str = [9 x i8] c"name=%s\0A\00"
@str.3 = [37 x i8] c"------------------------------------\00"
define i32 @main() {
%1 = tail call %struct.pig* (...) @init_pig()
%2 = tail call i8* @animal_get_name(%struct.pig* %1)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.3, i64 0, i64 0))
%5 = tail call %struct.pig* (...) @init_dog()
%6 = tail call i8* @animal_get_name(%struct.pig* %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.3, i64 0, i64 0))
%9 = tail call i8* @animal_get_name(%struct.pig* %1)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @animal_shout(%struct.pig* %1, i32 20)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.3, i64 0, i64 0))
%13 = tail call i8* @animal_get_name(%struct.pig* %5)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @animal_shout(%struct.pig* %5, i32 100)
ret i32 0
}