#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*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ s_gets(char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(void) {
  char qwords[5][7];
  char temp[40];
  int i = 0;
  printf("Enter %d words beginning with q:\n", 5);
  while (i < 5 && s_gets(temp, 40)) {
    if (temp[0] != 'q')
      printf("%s doesn't begin with q!\n", temp);
    else {
      strncpy(qwords[i], temp, 7 - 1);
      qwords[i][7 - 1] = '\0';
      i++;
    }
  }
  puts("Here are the words accepted:");
  for (i = 0; i < 5; i++)
    puts(qwords[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x64(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x5,%esi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
cmpl   $0x5,-0x64(%rbp)
mov    %al,-0x65(%rbp)
jge    1190 <main+0x50>
lea    -0x60(%rbp),%rdi
mov    $0x28,%esi
call   1050 <s_gets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x65(%rbp)
mov    -0x65(%rbp),%al
test   $0x1,%al
jne    11a0 <main+0x60>
jmp    1202 <main+0xc2>
movsbl -0x60(%rbp),%eax
cmp    $0x71,%eax
je     11c4 <main+0x84>
lea    -0x60(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11fd <main+0xbd>
movslq -0x64(%rbp),%rax
lea    -0x30(%rbp),%rdi
imul   $0x7,%rax,%rax
add    %rax,%rdi
lea    -0x60(%rbp),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
movslq -0x64(%rbp),%rcx
lea    -0x30(%rbp),%rax
imul   $0x7,%rcx,%rcx
add    %rcx,%rax
movb   $0x0,0x6(%rax)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1169 <main+0x29>
lea    0xe33(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0x5,-0x64(%rbp)
jge    1241 <main+0x101>
movslq -0x64(%rbp),%rax
lea    -0x30(%rbp),%rdi
imul   $0x7,%rax,%rax
add    %rax,%rdi
call   1040 <puts@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1215 <main+0xd5>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x58,%rsp
lea    0xeae(%rip),%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x30(%rsp),%r15
lea    0xeb8(%rip),%r14
xor    %r12d,%r12d
jmp    119e <main+0x5e>
nop
movslq %r12d,%r12
lea    0x0(,%r12,8),%rbx
sub    %r12,%rbx
lea    (%rsp,%rbx,1),%rdi
mov    %r15,%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x6(%rsp,%rbx,1)
add    $0x1,%r12d
cmp    $0x5,%r12d
jge    11ca <main+0x8a>
mov    %r15,%rdi
mov    $0x28,%esi
call   1050 <s_gets@plt>
test   %rax,%rax
je     11ca <main+0x8a>
cmpb   $0x71,0x30(%rsp)
je     1170 <main+0x30>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x5,%r12d
jl     119e <main+0x5e>
lea    0xe6b(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rdi
call   1040 <puts@plt>
lea    0x7(%rsp),%rdi
call   1040 <puts@plt>
lea    0xe(%rsp),%rdi
call   1040 <puts@plt>
lea    0x15(%rsp),%rdi
call   1040 <puts@plt>
lea    0x1c(%rsp),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Enter %d words beginning with q:\0A\00"
@.str.1 = [26 x i8] c"%s doesn't begin with q!\0A\00"
@.str.2 = [29 x i8] c"Here are the words accepted:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x [7 x i8]]
%3 = alloca [40 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 5)
br label %6
6: ; preds = %36, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 5
br i1 %8, label %9, label %13
9: ; preds = %6
%10 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%11 = call i64 @s_gets(i8* %10, i32 40)
%12 = icmp ne i64 %11, 0
br label %13
13: ; preds = %9, %6
%14 = phi i1 [ false, %6 ], [ %12, %9 ]
br i1 %14, label %15, label %37
15: ; preds = %13
%16 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 113
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %36
23: ; preds = %15
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [5 x [7 x i8]], [5 x [7 x i8]]* %2, i64 0, i64 %25
%27 = getelementptr inbounds [7 x i8], [7 x i8]* %26, i64 0, i64 0
%28 = getelementptr inbounds [40 x i8], [40 x i8]* %3, i64 0, i64 0
%29 = call i32 @strncpy(i8* %27, i8* %28, i32 6)
%30 = load i32, i32* %4
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [5 x [7 x i8]], [5 x [7 x i8]]* %2, i64 0, i64 %31
%33 = getelementptr inbounds [7 x i8], [7 x i8]* %32, i64 0, i64 6
store i8 0, i8* %33
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %36
36: ; preds = %23, %20
br label %6
37: ; preds = %13
%38 = call i32 @puts(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %4
br label %39
39: ; preds = %48, %37
%40 = load i32, i32* %4
%41 = icmp slt i32 %40, 5
br i1 %41, label %42, label %51
42: ; preds = %39
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [5 x [7 x i8]], [5 x [7 x i8]]* %2, i64 0, i64 %44
%46 = getelementptr inbounds [7 x i8], [7 x i8]* %45, i64 0, i64 0
%47 = call i32 @puts(i8* %46)
br label %48
48: ; preds = %42
%49 = load i32, i32* %4
%50 = add nsw i32 %49, 1
store i32 %50, i32* %4
br label %39
51: ; preds = %39
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Enter %d words beginning with q:\0A\00"
@.str.1 = [26 x i8] c"%s doesn't begin with q!\0A\00"
@.str.2 = [29 x i8] c"Here are the words accepted:\00"
define i32 @main() {
%1 = alloca [5 x [7 x i8]]
%2 = alloca [40 x i8]
%3 = getelementptr inbounds [5 x [7 x i8]], [5 x [7 x i8]]* %1, i64 0, i64 0, i64 0
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 5)
br label %6
6: ; preds = %0, %21
%7 = phi i32 [ 0, %0 ], [ %22, %21 ]
%8 = call i64 @s_gets(i8* %4, i32 40)
%9 = icmp eq i64 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %6
%11 = load i8, i8* %4
%12 = icmp eq i8 %11, 113
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %21
15: ; preds = %10
%16 = sext i32 %7 to i64
%17 = getelementptr inbounds [5 x [7 x i8]], [5 x [7 x i8]]* %1, i64 0, i64 %16, i64 0
%18 = call i32 @strncpy(i8* %17, i8* %4, i32 6)
%19 = getelementptr inbounds [5 x [7 x i8]], [5 x [7 x i8]]* %1, i64 0, i64 %16, i64 6
store i8 0, i8* %19
%20 = add nsw i32 %7, 1
br label %21
21: ; preds = %15, %13
%22 = phi i32 [ %7, %13 ], [ %20, %15 ]
%23 = icmp slt i32 %22, 5
br i1 %23, label %6, label %24
24: ; preds = %21, %6
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @puts(i8* %3)
%27 = getelementptr inbounds [5 x [7 x i8]], [5 x [7 x i8]]* %1, i64 0, i64 1, i64 0
%28 = call i32 @puts(i8* %27)
%29 = getelementptr inbounds [5 x [7 x i8]], [5 x [7 x i8]]* %1, i64 0, i64 2, i64 0
%30 = call i32 @puts(i8* %29)
%31 = getelementptr inbounds [5 x [7 x i8]], [5 x [7 x i8]]* %1, i64 0, i64 3, i64 0
%32 = call i32 @puts(i8* %31)
%33 = getelementptr inbounds [5 x [7 x i8]], [5 x [7 x i8]]* %1, i64 0, i64 4, i64 0
%34 = call i32 @puts(i8* %33)
ret i32 0
}