#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
void concatenate_first_chars() {
  struct {
    char word_buf[12];
    int i;
    char *cat_pointer;
    char cat_buf[10];
  } locals;
  locals.cat_pointer = locals.cat_buf;
  printf("Input 10 words:\n");
  for (locals.i = 0; locals.i != 10; locals.i++) {
    if (fgets(locals.word_buf, 0x10, stdin) == 0 ||
        locals.word_buf[0] == '\n') {
      printf("Failed to read word\n");
      return;
    }
    *locals.cat_pointer = *locals.word_buf;
    locals.cat_pointer++;
  }
  locals.cat_buf[10] = '\0';
  printf("Here are the first characters from the 10 words concatenated:\n%s\n",
         locals.cat_buf);
}


x86 assembly (clang, -O0):
<concatenate_first_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x28(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x18(%rbp)
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0xa,-0x1c(%rbp)
je     11b7 <concatenate_first_chars+0x97>
lea    -0x28(%rbp),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
mov    $0x10,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1181 <concatenate_first_chars+0x61>
movsbl -0x28(%rbp),%eax
cmp    $0xa,%eax
jne    1194 <concatenate_first_chars+0x74>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d1 <concatenate_first_chars+0xb1>
mov    -0x28(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <concatenate_first_chars+0x29>
movb   $0x0,-0x6(%rbp)
lea    -0x28(%rbp),%rsi
add    $0x18,%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<concatenate_first_chars>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0x20(%rsp),%r14
mov    %r14,0x18(%rsp)
lea    0xef8(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,0x14(%rsp)
mov    0x2e8a(%rip),%r15
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11c3 <concatenate_first_chars+0x93>
movzbl 0x8(%rsp),%eax
cmp    $0xa,%al
je     11c3 <concatenate_first_chars+0x93>
mov    0x18(%rsp),%rcx
mov    %al,(%rcx)
addq   $0x1,0x18(%rsp)
mov    0x14(%rsp),%eax
add    $0x1,%eax
mov    %eax,0x14(%rsp)
cmp    $0xa,%eax
jne    1170 <concatenate_first_chars+0x40>
movb   $0x0,0x2a(%rsp)
lea    0xe49(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11cf <concatenate_first_chars+0x9f>
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.anon = type { [12 x i8], i32, i8*, [10 x i8] }
@.str = [17 x i8] c"Input 10 words:\0A\00"
@stdin = global i32 0
@.str.1 = [21 x i8] c"Failed to read word\0A\00"
@.str.2 = [66 x i8] c"Here are the first characters from the 10 words concatenated:\0A%s\0A\00"
define void @concatenate_first_chars() {
%1 = alloca %struct.anon
%2 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 3
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 2
store i8* %3, i8** %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 1
store i32 0, i32* %6
br label %7
7: ; preds = %34, %0
%8 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 1
%9 = load i32, i32* %8
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %38
11: ; preds = %7
%12 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%13 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i64 @fgets(i8* %13, i32 16, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %11
%18 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%19 = getelementptr inbounds [12 x i8], [12 x i8]* %18, i64 0, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %25
23: ; preds = %17, %11
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %44
25: ; preds = %17
%26 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 0
%27 = getelementptr inbounds [12 x i8], [12 x i8]* %26, i64 0, i64 0
%28 = load i8, i8* %27
%29 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 2
%30 = load i8*, i8** %29
store i8 %28, i8* %30
%31 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 2
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %31
br label %34
34: ; preds = %25
%35 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 1
%36 = load i32, i32* %35
%37 = add nsw i32 %36, 1
store i32 %37, i32* %35
br label %7
38: ; preds = %7
%39 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 3
%40 = getelementptr inbounds [10 x i8], [10 x i8]* %39, i64 0, i64 10
store i8 0, i8* %40
%41 = getelementptr inbounds %struct.anon, %struct.anon* %1, i32 0, i32 3
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %41, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %38, %23
ret void
}

LLVM IR (-O2):
%struct.anon = type { [12 x i8], i32, i8*, [10 x i8] }
@stdin = global i32 0
@.str.2 = [66 x i8] c"Here are the first characters from the 10 words concatenated:\0A%s\0A\00"
@str = [16 x i8] c"Input 10 words:\00"
@str.3 = [20 x i8] c"Failed to read word\00"
define void @concatenate_first_chars() {
%1 = alloca %struct.anon
%2 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 0, i64 0
%3 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 3, i64 0
%4 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 2
store i8* %3, i8** %4
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%6 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 1
store i32 0, i32* %6
br label %7
7: ; preds = %0, %16
%8 = load i32, i32* @stdin
%9 = call i64 @fgets(i8* %2, i32 16, i32 %8)
%10 = icmp eq i64 %9, 0
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 10
%13 = select i1 %10, i1 true, i1 %12
br i1 %13, label %14, label %16
14: ; preds = %7
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.3, i64 0, i64 0))
br label %26
16: ; preds = %7
%17 = load i8*, i8** %4
store i8 %11, i8* %17
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
store i8* %19, i8** %4
%20 = load i32, i32* %6
%21 = add nsw i32 %20, 1
store i32 %21, i32* %6
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %7
23: ; preds = %16
%24 = getelementptr inbounds %struct.anon, %struct.anon* %1, i64 0, i32 3, i64 10
store i8 0, i8* %24
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %26
26: ; preds = %23, %14
ret void
}