#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 foo(int, int, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int ret = foo(123, 321, "hello world");
  printf("ret = %d\n", ret);
  char stack_str[10];
  stack_str[0] = 'q';
  stack_str[1] = 'z';
  stack_str[2] = '!';
  short stack_shorts[10];
  stack_shorts[1] = 1;
  stack_shorts[3] = 3;
  stack_shorts[5] = 5;
  stack_shorts[7] = 7;
  stack_shorts[9] = 9;
  char *heap_str = (char *)malloc(7);
  heap_str[0] = 'B';
  heap_str[1] = 'o';
  heap_str[2] = 'b';
  heap_str[3] = '\0';
  heap_str++;
  heap_str++;
  heap_str++;
  unsigned short *heap_shorts =
      (unsigned short *)malloc(11 * sizeof(*heap_shorts));
  heap_shorts[1] = 1;
  heap_shorts[3] = 3;
  heap_shorts[5] = 5;
  heap_shorts[7] = 7;
  heap_shorts[9] = 9;
  heap_shorts++;
  heap_shorts++;
  heap_shorts++;
  ret = foo(333, 444, stack_str);
  printf("ret = %d\n", ret);
  return 42;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x7b,%edi
mov    $0x141,%esi
lea    0xeb0(%rip),%rdx
call   1050 <foo@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xeaa(%rip),%rdi
call   1030 <printf@plt>
movb   $0x71,-0x12(%rbp)
movb   $0x7a,-0x11(%rbp)
movb   $0x21,-0x10(%rbp)
movw   $0x1,-0x2e(%rbp)
movw   $0x3,-0x2a(%rbp)
movw   $0x5,-0x26(%rbp)
movw   $0x7,-0x22(%rbp)
movw   $0x9,-0x1e(%rbp)
mov    $0x7,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movb   $0x42,(%rax)
mov    -0x38(%rbp),%rax
movb   $0x6f,0x1(%rax)
mov    -0x38(%rbp),%rax
movb   $0x62,0x2(%rax)
mov    -0x38(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    $0x16,%edi
call   1040 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movw   $0x1,0x2(%rax)
mov    -0x40(%rbp),%rax
movw   $0x3,0x6(%rax)
mov    -0x40(%rbp),%rax
movw   $0x5,0xa(%rax)
mov    -0x40(%rbp),%rax
movw   $0x7,0xe(%rax)
mov    -0x40(%rbp),%rax
movw   $0x9,0x12(%rax)
mov    -0x40(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x40(%rbp)
lea    -0x12(%rbp),%rdx
mov    $0x14d,%edi
mov    $0x1bc,%esi
call   1050 <foo@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xda6(%rip),%rdi
call   1030 <printf@plt>
mov    $0x2a,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdx
mov    $0x7b,%edi
mov    $0x141,%esi
call   1050 <foo@plt>
lea    0xeba(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
movw   $0x7a71,0x6(%rsp)
movb   $0x21,0x8(%rsp)
mov    $0x7,%edi
call   1040 <malloc@plt>
movl   $0x626f42,(%rax)
mov    $0x16,%edi
call   1040 <malloc@plt>
movw   $0x1,0x2(%rax)
movw   $0x3,0x6(%rax)
movw   $0x5,0xa(%rax)
movw   $0x7,0xe(%rax)
movw   $0x9,0x12(%rax)
lea    0x6(%rsp),%rdx
mov    $0x14d,%edi
mov    $0x1bc,%esi
call   1050 <foo@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x2a,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [10 x i8] c"ret = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [10 x i8]
%4 = alloca [10 x i16]
%5 = alloca i8*
%6 = alloca i16*
store i32 0, i32* %1
%7 = call i32 @foo(i32 123, i32 321, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
store i8 113, i8* %10
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 1
store i8 122, i8* %11
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 2
store i8 33, i8* %12
%13 = getelementptr inbounds [10 x i16], [10 x i16]* %4, i64 0, i64 1
store i16 1, i16* %13
%14 = getelementptr inbounds [10 x i16], [10 x i16]* %4, i64 0, i64 3
store i16 3, i16* %14
%15 = getelementptr inbounds [10 x i16], [10 x i16]* %4, i64 0, i64 5
store i16 5, i16* %15
%16 = getelementptr inbounds [10 x i16], [10 x i16]* %4, i64 0, i64 7
store i16 7, i16* %16
%17 = getelementptr inbounds [10 x i16], [10 x i16]* %4, i64 0, i64 9
store i16 9, i16* %17
%18 = call i64 @malloc(i32 7)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %5
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 66, i8* %21
%22 = load i8*, i8** %5
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 111, i8* %23
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 2
store i8 98, i8* %25
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 3
store i8 0, i8* %27
%28 = load i8*, i8** %5
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %5
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %5
%34 = call i64 @malloc(i32 22)
%35 = inttoptr i64 %34 to i16*
store i16* %35, i16** %6
%36 = load i16*, i16** %6
%37 = getelementptr inbounds i16, i16* %36, i64 1
store i16 1, i16* %37
%38 = load i16*, i16** %6
%39 = getelementptr inbounds i16, i16* %38, i64 3
store i16 3, i16* %39
%40 = load i16*, i16** %6
%41 = getelementptr inbounds i16, i16* %40, i64 5
store i16 5, i16* %41
%42 = load i16*, i16** %6
%43 = getelementptr inbounds i16, i16* %42, i64 7
store i16 7, i16* %43
%44 = load i16*, i16** %6
%45 = getelementptr inbounds i16, i16* %44, i64 9
store i16 9, i16* %45
%46 = load i16*, i16** %6
%47 = getelementptr inbounds i16, i16* %46, i32 1
store i16* %47, i16** %6
%48 = load i16*, i16** %6
%49 = getelementptr inbounds i16, i16* %48, i32 1
store i16* %49, i16** %6
%50 = load i16*, i16** %6
%51 = getelementptr inbounds i16, i16* %50, i32 1
store i16* %51, i16** %6
%52 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%53 = call i32 @foo(i32 333, i32 444, i8* %52)
store i32 %53, i32* %2
%54 = load i32, i32* %2
%55 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %54)
ret i32 42
}

LLVM IR (-O2):
@.str = [12 x i8] c"hello world\00"
@.str.1 = [10 x i8] c"ret = %d\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = tail call i32 @foo(i32 123, i32 321, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
store i8 113, i8* %4
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 1
store i8 122, i8* %5
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 2
store i8 33, i8* %6
%7 = tail call i64 @malloc(i32 7)
%8 = inttoptr i64 %7 to i8*
store i8 66, i8* %8
%9 = getelementptr inbounds i8, i8* %8, i64 1
store i8 111, i8* %9
%10 = getelementptr inbounds i8, i8* %8, i64 2
store i8 98, i8* %10
%11 = getelementptr inbounds i8, i8* %8, i64 3
store i8 0, i8* %11
%12 = tail call i64 @malloc(i32 22)
%13 = inttoptr i64 %12 to i16*
%14 = getelementptr inbounds i16, i16* %13, i64 1
store i16 1, i16* %14
%15 = getelementptr inbounds i16, i16* %13, i64 3
store i16 3, i16* %15
%16 = getelementptr inbounds i16, i16* %13, i64 5
store i16 5, i16* %16
%17 = getelementptr inbounds i16, i16* %13, i64 7
store i16 7, i16* %17
%18 = getelementptr inbounds i16, i16* %13, i64 9
store i16 9, i16* %18
%19 = call i32 @foo(i32 333, i32 444, i8* %4)
%20 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %19)
ret i32 42
}