#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*/ strcat_s(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy_s(char *, int, int /*<<< orphan*/);
int main(void) {
  struct {
    char buf[8];
    int var;
  } v = {"", 0x55555555};
  strcpy_s(v.buf, sizeof(v.buf), getenv("ASDF"));
  strcat_s(v.buf, sizeof(v.buf), getenv("FRRR"));
  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,%edx
mov    $0x8,%esi
call   1060 <strcpy_s@plt>
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe7b(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,%edx
mov    $0x8,%esi
call   1040 <strcat_s@plt>
lea    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe5d(%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    $0x8,%esi
mov    %eax,%edx
call   1060 <strcpy_s@plt>
lea    0xe92(%rip),%rdi
call   1030 <getenv@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
mov    %eax,%edx
call   1040 <strcat_s@plt>
mov    0x8(%rsp),%edx
lea    0xe78(%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 @strcpy_s(i8* %5, i32 8, i32 %6)
%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 0
%10 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @strcat_s(i8* %9, i32 8, i32 %10)
%12 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 0
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%14 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 1
%15 = load i32, i32* %14
%16 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %13, i32 %15)
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 @strcpy_s(i8* %2, i32 8, i32 %3)
%5 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @strcat_s(i8* %2, i32 8, i32 %5)
%7 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1
%8 = load i32, i32* %7
%9 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %8)
ret i32 0
}