#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*/ strncat(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int main(void) {
  struct {
    char buf[8];
    int var;
  } v = {"", 0x55555555};
  strncpy(v.buf, getenv("ASDF"), sizeof(v.buf) - 1);
  v.buf[sizeof(v.buf) - 1] = '\0';
  strncat(v.buf, getenv("FRRR"), sizeof(v.buf) - 1);
  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    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xea8(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe9a(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
mov    $0x7,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x9(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe77(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%esi
mov    $0x7,%edx
call   1060 <strncat@plt>
lea    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe59(%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    0xebd(%rip),%eax
mov    %eax,0x8(%rsp)
mov    0xeaa(%rip),%rax
mov    %rax,(%rsp)
lea    0xeab(%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)
lea    0xe8d(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x7,%edx
call   1060 <strncat@plt>
mov    0x8(%rsp),%edx
lea    0xe73(%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 1431655765 }
@.str = [5 x i8] c"ASDF\00"
@.str.1 = [5 x i8] c"FRRR\00"
@.str.2 = [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 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @strncat(i8* %11, i32 %12, i32 7)
%14 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 0
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %14, i64 0, i64 0
%16 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 1
%17 = load i32, i32* %16
%18 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32 %17)
ret i32 0
}

LLVM IR (-O2):
%struct.anon = type { [8 x i8], i32 }
@__const.main.v = %struct.anon { [8 x i8] zeroinitializer, i32 1431655765 }
@.str = [5 x i8] c"ASDF\00"
@.str.1 = [5 x i8] c"FRRR\00"
@.str.2 = [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 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @strncat(i8* %2, i32 %6, i32 7)
%8 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1
%9 = load i32, i32* %8
%10 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %9)
ret i32 0
}