#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char **argv) {
  char sendline[100];
  char buffer[100];
  int c = 0;
  int d = 0;
  int i = 0;
  memset(buffer, 0, sizeof(buffer));
  while (i <= 3) {
    fgets(sendline, 100, stdin);
    d = strlen(sendline) - 1;
    printf("%d\n", d);
    if (d <= 0)
      break;
    memcpy(buffer + c, sendline, d);
    c += d;
    printf("%d\n", c);
    i++;
  }
  printf("buffer = %s\n", buffer);
  char cmd_key[32];
  memcpy(cmd_key, "put ", 4);
  fgets(cmd_key + 4, 32, stdin);
  printf("cmd & key = %s\n", cmd_key);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xf4(%rbp)
movl   $0x0,-0xf8(%rbp)
movl   $0x0,-0xfc(%rbp)
lea    -0xf0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
cmpl   $0x3,-0xfc(%rbp)
jg     1250 <main+0x100>
lea    -0x80(%rbp),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0xf8(%rbp)
mov    -0xf8(%rbp),%esi
lea    0xe23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0xf8(%rbp)
jg     11f6 <main+0xa6>
jmp    1250 <main+0x100>
lea    -0xf0(%rbp),%rdi
movslq -0xf4(%rbp),%rax
add    %rax,%rdi
lea    -0x80(%rbp),%rsi
mov    -0xf8(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0xf8(%rbp),%eax
add    -0xf4(%rbp),%eax
mov    %eax,-0xf4(%rbp)
mov    -0xf4(%rbp),%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xfc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfc(%rbp)
jmp    119a <main+0x4a>
lea    -0xf0(%rbp),%rsi
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x120(%rbp),%rdi
lea    0xd9e(%rip),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    -0x120(%rbp),%rdi
add    $0x4,%rdi
mov    0x2d59(%rip),%rax
mov    (%rax),%edx
mov    $0x20,%esi
call   1060 <fgets@plt>
lea    -0x120(%rbp),%rsi
lea    0xd6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
lea    0x20(%rsp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1050 <memset@plt>
mov    0x2e71(%rip),%r12
mov    (%r12),%edx
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%ebp
lea    0xe5c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebx
jl     130e <main+0x1be>
lea    0x20(%rsp),%rdi
lea    0x90(%rsp),%rbx
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
lea    0xe2c(%rip),%r14
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%r15d
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebx
jl     130e <main+0x1be>
mov    %ebp,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x20,%rdi
lea    0x90(%rsp),%rbx
mov    %rbx,%rsi
mov    %r15d,%edx
call   1070 <memcpy@plt>
add    %ebp,%r15d
lea    0xdc4(%rip),%r14
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebx
jl     130e <main+0x1be>
mov    %r15d,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x20,%rdi
lea    0x90(%rsp),%rbx
mov    %rbx,%rsi
mov    %ebp,%edx
call   1070 <memcpy@plt>
add    %r15d,%ebp
lea    0xd5d(%rip),%r14
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%r15d
mov    %r14,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebx
jl     130e <main+0x1be>
mov    %ebp,%eax
lea    (%rsp,%rax,1),%rdi
add    $0x20,%rdi
lea    0x90(%rsp),%rsi
mov    %r15d,%edx
call   1070 <memcpy@plt>
add    %ebp,%r15d
lea    0xcfc(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xcef(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xce9(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    0x4(%rsp),%rdi
mov    (%r12),%edx
mov    $0x20,%esi
call   1060 <fgets@plt>
lea    0xcc4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [13 x i8] c"buffer = %s\0A\00"
@.str.2 = [5 x i8] c"put \00"
@.str.3 = [16 x i8] c"cmd & key = %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [32 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 100)
br label %14
14: ; preds = %29, %2
%15 = load i32, i32* %10
%16 = icmp sle i32 %15, 3
br i1 %16, label %17, label %44
17: ; preds = %14
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 100, i32 %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = sub nsw i32 %22, 1
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %9
%27 = icmp sle i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %17
br label %44
29: ; preds = %17
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%31 = load i32, i32* %8
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* %9
%36 = call i32 @memcpy(i8* %33, i8* %34, i32 %35)
%37 = load i32, i32* %9
%38 = load i32, i32* %8
%39 = add nsw i32 %38, %37
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = load i32, i32* %10
%43 = add nsw i32 %42, 1
store i32 %43, i32* %10
br label %14
44: ; preds = %28, %14
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%48 = call i32 @memcpy(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%50 = getelementptr inbounds i8, i8* %49, i64 4
%51 = load i32, i32* @stdin
%52 = call i32 @fgets(i8* %50, i32 32, i32 %51)
%53 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %53)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [13 x i8] c"buffer = %s\0A\00"
@.str.2 = [5 x i8] c"put \00"
@.str.3 = [16 x i8] c"cmd & key = %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 100)
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %6, i32 100, i32 %9)
%11 = call i32 @strlen(i8* %6)
%12 = add nsw i32 %11, -1
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = icmp slt i32 %11, 2
br i1 %14, label %54, label %15
15: ; preds = %2
%16 = call i32 @memcpy(i8* %7, i8* %6, i32 %12)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %12)
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %6, i32 100, i32 %18)
%20 = call i32 @strlen(i8* %6)
%21 = add nsw i32 %20, -1
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = icmp slt i32 %20, 2
br i1 %23, label %54, label %24
24: ; preds = %15
%25 = zext i32 %12 to i64
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %25
%27 = call i32 @memcpy(i8* %26, i8* %6, i32 %21)
%28 = add nuw nsw i32 %21, %12
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* @stdin
%31 = call i32 @fgets(i8* %6, i32 100, i32 %30)
%32 = call i32 @strlen(i8* %6)
%33 = add nsw i32 %32, -1
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %33)
%35 = icmp slt i32 %32, 2
br i1 %35, label %54, label %36
36: ; preds = %24
%37 = zext i32 %28 to i64
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %37
%39 = call i32 @memcpy(i8* %38, i8* %6, i32 %33)
%40 = add nuw nsw i32 %33, %28
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
%42 = load i32, i32* @stdin
%43 = call i32 @fgets(i8* %6, i32 100, i32 %42)
%44 = call i32 @strlen(i8* %6)
%45 = add nsw i32 %44, -1
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %45)
%47 = icmp slt i32 %44, 2
br i1 %47, label %54, label %48
48: ; preds = %36
%49 = zext i32 %40 to i64
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %49
%51 = call i32 @memcpy(i8* %50, i8* %6, i32 %45)
%52 = add nuw nsw i32 %45, %40
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %48, %36, %24, %15, %2
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%56 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%57 = call i32 @memcpy(i8* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 4)
%58 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 4
%59 = load i32, i32* @stdin
%60 = call i32 @fgets(i8* %58, i32 32, i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %56)
ret i32 0
}