#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*/ bar();
int /*<<< orphan*/ foo(int *, int *, unsigned int *);
int *malloc(int);
int main(void) {
  unsigned int hack;
  int *junk1 = malloc(sizeof(int));
  int *junk2 = malloc(sizeof(int));
  short *ps1 = (short *)junk1;
  short *ps2 = (short *)junk2;
  int *pi1 = (int *)junk1;
  int *pi2 = (int *)junk2;
  bar();
  foo(pi1, pi2, &hack);
  *ps1 = 41;
  *ps2 = 42;
  foo(pi1, pi2, &hack);
  *ps1 = 42;
  *ps2 = 42;
  foo(pi1, pi2, &hack);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <bar@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <foo@plt>
mov    -0x20(%rbp),%rax
movw   $0x29,(%rax)
mov    -0x28(%rbp),%rax
movw   $0x2a,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <foo@plt>
mov    -0x20(%rbp),%rax
movw   $0x2a,(%rax)
mov    -0x28(%rbp),%rax
movw   $0x2a,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
lea    -0x8(%rbp),%rdx
call   1050 <foo@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <bar@plt>
lea    0xc(%rsp),%r15
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <foo@plt>
movw   $0x29,(%r14)
movw   $0x2a,(%rbx)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <foo@plt>
movw   $0x2a,(%r14)
movw   $0x2a,(%rbx)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <foo@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i16*
%6 = alloca i16*
%7 = alloca i32*
%8 = alloca i32*
store i32 0, i32* %1
%9 = call i32* @malloc(i32 4)
store i32* %9, i32** %3
%10 = call i32* @malloc(i32 4)
store i32* %10, i32** %4
%11 = load i32*, i32** %3
%12 = bitcast i32* %11 to i16*
store i16* %12, i16** %5
%13 = load i32*, i32** %4
%14 = bitcast i32* %13 to i16*
store i16* %14, i16** %6
%15 = load i32*, i32** %3
store i32* %15, i32** %7
%16 = load i32*, i32** %4
store i32* %16, i32** %8
%17 = call i32 (...) @bar()
%18 = load i32*, i32** %7
%19 = load i32*, i32** %8
%20 = call i32 @foo(i32* %18, i32* %19, i32* %2)
%21 = load i16*, i16** %5
store i16 41, i16* %21
%22 = load i16*, i16** %6
store i16 42, i16* %22
%23 = load i32*, i32** %7
%24 = load i32*, i32** %8
%25 = call i32 @foo(i32* %23, i32* %24, i32* %2)
%26 = load i16*, i16** %5
store i16 42, i16* %26
%27 = load i16*, i16** %6
store i16 42, i16* %27
%28 = load i32*, i32** %7
%29 = load i32*, i32** %8
%30 = call i32 @foo(i32* %28, i32* %29, i32* %2)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @malloc(i32 4)
%4 = tail call i32* @malloc(i32 4)
%5 = bitcast i32* %3 to i16*
%6 = bitcast i32* %4 to i16*
%7 = tail call i32 (...) @bar()
%8 = call i32 @foo(i32* %3, i32* %4, i32* %1)
store i16 41, i16* %5
store i16 42, i16* %6
%9 = call i32 @foo(i32* %3, i32* %4, i32* %1)
store i16 42, i16* %5
store i16 42, i16* %6
%10 = call i32 @foo(i32* %3, i32* %4, i32* %1)
ret i32 0
}