#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 *, int);
int /*<<< orphan*/ useGlobal();
int /*<<< orphan*/ useLocal();
int /*<<< orphan*/ useStaticLocal();
void fig05_16() {
  int x = 5;
  printf("local x in outer scope of fig05_16 is %d\n", x);
  {
    int x = 7;
    printf("local x in inner scope of fig05_16 is %d\n", x);
  }
  printf("local x in outer scope of fig05_16 is %d\n", x);
  useLocal();
  useStaticLocal();
  useGlobal();
  useLocal();
  useStaticLocal();
  useGlobal();
  printf("\nlocal x in fig05_16 is %d\n", x);
}


x86 assembly (clang, -O0):
<fig05_16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x5,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xea7(%rip),%rdi
call   1030 <printf@plt>
movl   $0x7,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%esi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <useLocal@plt>
mov    $0x0,%al
call   1040 <useStaticLocal@plt>
mov    $0x0,%al
call   1050 <useGlobal@plt>
mov    $0x0,%al
call   1060 <useLocal@plt>
mov    $0x0,%al
call   1040 <useStaticLocal@plt>
mov    $0x0,%al
call   1050 <useGlobal@plt>
mov    -0x4(%rbp),%esi
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fig05_16>:
push   %rbx
lea    0xeb8(%rip),%rbx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
lea    0xece(%rip),%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <useLocal@plt>
xor    %eax,%eax
call   1040 <useStaticLocal@plt>
xor    %eax,%eax
call   1050 <useGlobal@plt>
xor    %eax,%eax
call   1060 <useLocal@plt>
xor    %eax,%eax
call   1040 <useStaticLocal@plt>
xor    %eax,%eax
call   1050 <useGlobal@plt>
lea    0xeb0(%rip),%rdi
mov    $0x5,%esi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"local x in outer scope of fig05_16 is %d\0A\00"
@.str.1 = [42 x i8] c"local x in inner scope of fig05_16 is %d\0A\00"
@.str.2 = [28 x i8] c"\0Alocal x in fig05_16 is %d\0A\00"
define void @fig05_16() {
%1 = alloca i32
%2 = alloca i32
store i32 5, i32* %1
%3 = load i32, i32* %1
%4 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 7, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 (...) @useLocal()
%10 = call i32 (...) @useStaticLocal()
%11 = call i32 (...) @useGlobal()
%12 = call i32 (...) @useLocal()
%13 = call i32 (...) @useStaticLocal()
%14 = call i32 (...) @useGlobal()
%15 = load i32, i32* %1
%16 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %15)
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"local x in outer scope of fig05_16 is %d\0A\00"
@.str.1 = [42 x i8] c"local x in inner scope of fig05_16 is %d\0A\00"
@.str.2 = [28 x i8] c"\0Alocal x in fig05_16 is %d\0A\00"
define void @fig05_16() {
%1 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 5)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 7)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 5)
%4 = tail call i32 (...) @useLocal()
%5 = tail call i32 (...) @useStaticLocal()
%6 = tail call i32 (...) @useGlobal()
%7 = tail call i32 (...) @useLocal()
%8 = tail call i32 (...) @useStaticLocal()
%9 = tail call i32 (...) @useGlobal()
%10 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 5)
ret void
}