void fun2(int fd) {
  int i = 1;
  printf("sup: %s, local var at %p\n", __func__, &i);
  int rc;
  char buf[1024];
  rc = read(fd, (void *)buf, 1024);
  buf[rc] = '\0';
  printf("sup: %s\n", buf);
}


x86 assembly (clang, -O0):
<fun2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
lea    0xec4(%rip),%rdi
lea    0xed7(%rip),%rsi
lea    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun2>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
lea    0xec5(%rip),%rdi
lea    0xed8(%rip),%rsi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %eax,%eax
call   1040 <read@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xead(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [26 x i8] c"sup: %s, local var at %p\0A\00"
@__func__.fun2 = [5 x i8] c"fun2\00"
@.str.1 = [9 x i8] c"sup: %s\0A\00"
define void @fun2(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1024 x i8]
store i32 %0, i32* %2
store i32 1, i32* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.fun2, i64 0, i64 0), i32* %3)
%7 = load i32, i32* %2
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %7, i8* %8, i32 1024)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %11
store i8 0, i8* %12
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %13)
ret void
}

LLVM IR (-O2):
@.str = [26 x i8] c"sup: %s, local var at %p\0A\00"
@__func__.fun2 = [5 x i8] c"fun2\00"
@.str.1 = [9 x i8] c"sup: %s\0A\00"
define void @fun2(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__func__.fun2, i64 0, i64 0), i32* %2)
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 (i32, i8*, i32, ...) bitcast (i32 (...)* @read to i32 (i32, i8*, i32, ...)*)(i32 %0, i8* %6, i32 1024)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %8
store i8 0, i8* %9
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %6)
ret void
}