#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);
size_t strlen(char *);
int /*<<< orphan*/ strncat(char *, int /*<<< orphan*/, size_t);
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';
  size_t buf_len = strlen(v.buf);
  if (buf_len < sizeof(v.buf) - 1) {
    size_t buf_left = sizeof(v.buf) - 1 - buf_len;
    strncat(v.buf, getenv("FRRR"), buf_left);
  }
  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    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xe98(%rip),%eax
mov    %eax,-0x8(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe8a(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
mov    $0x7,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x9(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x7,-0x18(%rbp)
jae    11e3 <main+0x93>
mov    $0x7,%eax
sub    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe42(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
call   1070 <strncat@plt>
lea    -0x10(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xe25(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    0xead(%rip),%eax
mov    %eax,0x8(%rsp)
mov    0xe9a(%rip),%rax
mov    %rax,(%rsp)
lea    0xe9b(%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    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x6,%rax
ja     11bc <main+0x6c>
mov    $0x7,%ebx
sub    %rax,%rbx
lea    0xe67(%rip),%rdi
call   1030 <getenv@plt>
mov    %rsp,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1070 <strncat@plt>
mov    0x8(%rsp),%edx
lea    0xe4f(%rip),%rdi
mov    %rsp,%rsi
call   1060 <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
%3 = alloca i64
%4 = alloca i64
store i32 0, i32* %1
%5 = bitcast %struct.anon* %2 to i8*
%6 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 0
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%8 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @strncpy(i8* %7, i32 %8, i32 7)
%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 7
store i8 0, i8* %11
%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 = call i64 @strlen(i8* %13)
store i64 %14, i64* %3
%15 = load i64, i64* %3
%16 = icmp ult i64 %15, 7
br i1 %16, label %17, label %25
17: ; preds = %0
%18 = load i64, i64* %3
%19 = sub i64 7, %18
store i64 %19, i64* %4
%20 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 0
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %20, i64 0, i64 0
%22 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = load i64, i64* %4
%24 = call i32 @strncat(i8* %21, i32 %22, i64 %23)
br label %25
25: ; preds = %17, %0
%26 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 0
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %26, i64 0, i64 0
%28 = getelementptr inbounds %struct.anon, %struct.anon* %2, i32 0, i32 1
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %27, i32 %29)
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 i64 @strlen(i8* %2)
%7 = icmp ult i64 %6, 7
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = sub nuw nsw i64 7, %6
%10 = call i32 @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @strncat(i8* %2, i32 %10, i64 %9)
br label %12
12: ; preds = %8, %0
%13 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1
%14 = load i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %2, i32 %14)
ret i32 0
}