char *gen_key(void) {
  int i;
  int pick(int min, int max);
  static char key[6 + 1];
  for (i = 0; i < 6; i++) {
    key[i] = pick(' ' + 1, '~');
  }
  key[i] = '\0';
  return key;
}


x86 assembly (clang, -O0):
<gen_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x6,-0x4(%rbp)
jge    1156 <gen_key+0x46>
mov    $0x21,%edi
mov    $0x7e,%esi
call   1030 <pick@plt>
mov    %al,%dl
movslq -0x4(%rbp),%rcx
lea    0x2ee4(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    111f <gen_key+0xf>
movslq -0x4(%rbp),%rcx
lea    0x2ec8(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ebd(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_key>:
push   %rbx
mov    $0x21,%edi
mov    $0x7e,%esi
call   1030 <pick@plt>
mov    %al,0x2f03(%rip)
lea    0x2efc(%rip),%rbx
mov    $0x21,%edi
mov    $0x7e,%esi
call   1030 <pick@plt>
mov    %al,0x2ee8(%rip)
mov    $0x21,%edi
mov    $0x7e,%esi
call   1030 <pick@plt>
mov    %al,0x2ed4(%rip)
mov    $0x21,%edi
mov    $0x7e,%esi
call   1030 <pick@plt>
mov    %al,0x2ec0(%rip)
mov    $0x21,%edi
mov    $0x7e,%esi
call   1030 <pick@plt>
mov    %al,0x2eac(%rip)
mov    $0x21,%edi
mov    $0x7e,%esi
call   1030 <pick@plt>
mov    %al,0x2e98(%rip)
movb   $0x0,0x2e92(%rip)
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@gen_key.key = internal global [7 x i8] zeroinitializer
define i8* @gen_key() {
%1 = alloca i32
store i32 0, i32* %1
br label %2
2: ; preds = %11, %0
%3 = load i32, i32* %1
%4 = icmp slt i32 %3, 6
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = call i32 @pick(i32 33, i32 126)
%7 = trunc i32 %6 to i8
%8 = load i32, i32* %1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 %9
store i8 %7, i8* %10
br label %11
11: ; preds = %5
%12 = load i32, i32* %1
%13 = add nsw i32 %12, 1
store i32 %13, i32* %1
br label %2
14: ; preds = %2
%15 = load i32, i32* %1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 %16
store i8 0, i8* %17
ret i8* getelementptr inbounds ([7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 0)
}

LLVM IR (-O2):
@gen_key.key = internal global [7 x i8] zeroinitializer
define i8* @gen_key() {
%1 = tail call i32 @pick(i32 33, i32 126)
%2 = trunc i32 %1 to i8
store i8 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 0)
%3 = tail call i32 @pick(i32 33, i32 126)
%4 = trunc i32 %3 to i8
store i8 %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 1)
%5 = tail call i32 @pick(i32 33, i32 126)
%6 = trunc i32 %5 to i8
store i8 %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 2)
%7 = tail call i32 @pick(i32 33, i32 126)
%8 = trunc i32 %7 to i8
store i8 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 3)
%9 = tail call i32 @pick(i32 33, i32 126)
%10 = trunc i32 %9 to i8
store i8 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 4)
%11 = tail call i32 @pick(i32 33, i32 126)
%12 = trunc i32 %11 to i8
store i8 %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 5)
store i8 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 6)
ret i8* getelementptr inbounds ([7 x i8], [7 x i8]* @gen_key.key, i64 0, i64 0)
}