#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*/ getenv(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int main(void) {
  struct {
    char buf[8];
    int var;
  } v = {"", 0x00555555};
  strncpy(v.buf, getenv("ASDF"), sizeof(v.buf) - 1);
  v.buf[sizeof(v.buf) - 1] = '\0';
  printf("char buf[8] = \"%s\"\n"
         "int var = 0x%.8x\n",
         v.buf, v.var);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xeb8(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
mov    $0x7,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x9(%rbp)
lea    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe88(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0xecd(%rip),%eax
mov    %eax,0x8(%rsp)
mov    0xeba(%rip),%rax
mov    %rax,(%rsp)
lea    0xebb(%rip),%rdi
call   1030 <getenv@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x7,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x7(%rsp)
mov    0x8(%rsp),%edx
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.anon = type { [8 x i8], i32 }
@__const.main.v = %struct.anon { [8 x i8] zeroinitializer, i32 5592405 }
@.str = [5 x i8] c"ASDF\00"
@.str.1 = [37 x i8] c"char buf[8] = \22%s\22\0Aint var = 0x%.8x\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.anon
store i32 0, i32* %1
%3 = bitcast %struct.anon* %2 to i8*
%4 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 0
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%6 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @strncpy(i8* %5, i32 %6, i32 7)
%8 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 0
%9 = getelementptr inbounds [8 x i8], [8 x i8]* %8, i64 0, i64 7
store i8 0, i8* %9
%10 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 0
%11 = getelementptr inbounds [8 x i8], [8 x i8]* %10, i64 0, i64 0
%12 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 1
%13 = load i32, i32* %12
%14 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %13)
ret i32 0
}

LLVM IR (-O2):
%struct.anon = type { [8 x i8], i32 }
@__const.main.v = %struct.anon { [8 x i8] zeroinitializer, i32 5592405 }
@.str = [5 x i8] c"ASDF\00"
@.str.1 = [37 x i8] c"char buf[8] = \22%s\22\0Aint var = 0x%.8x\0A\00"
define i32 @main() {
%1 = alloca %struct.anon
%2 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 0, i64 0
%3 = tail call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @strncpy(i8* %2, i32 %3, i32 7)
%5 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 0, i64 7
store i8 0, i8* %5
%6 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1
%7 = load i32, i32* %6
%8 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %7)
ret i32 0
}