#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int main() {
  int i, count = 0;
  char s1[30];
  gets(s1);
  char s2[30];
  for (i = 0; s1[i] != '\0'; i++) {
    s2[i] = s1[i];
    count++;
  }
  s2[i] = '\0';
  puts(s2);
  printf("%d char copied", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
call   1050 <gets@plt>
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rax
movsbl -0x30(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     118f <main+0x5f>
movslq -0x8(%rbp),%rax
mov    -0x30(%rbp,%rax,1),%cl
movslq -0x8(%rbp),%rax
mov    %cl,-0x50(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <main+0x26>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
call   1030 <puts@plt>
mov    -0xc(%rbp),%esi
lea    0xe55(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
lea    0x20(%rsp),%rdi
call   1050 <gets@plt>
mov    0x20(%rsp),%cl
xor    %eax,%eax
test   %cl,%cl
je     1164 <main+0x34>
nopl   0x0(%rax)
mov    %cl,(%rsp,%rax,1)
movzbl 0x21(%rsp,%rax,1),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1150 <main+0x20>
mov    %eax,%ebx
jmp    1166 <main+0x36>
xor    %ebx,%ebx
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1030 <puts@plt>
lea    0xe87(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%d char copied\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [30 x i8]
%5 = alloca [30 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%7 = call i32 @gets(i8* %6)
store i32 0, i32* %2
br label %8
8: ; preds = %25, %0
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %8
%16 = load i32, i32* %2
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %21
store i8 %19, i8* %22
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %25
25: ; preds = %15
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %8
28: ; preds = %8
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 %30
store i8 0, i8* %31
%32 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%33 = call i32 @puts(i8* %32)
%34 = load i32, i32* %3
%35 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %34)
ret i32 0
}

LLVM IR (-O2):
@.str = [15 x i8] c"%d char copied\00"
define i32 @main() {
%1 = alloca [30 x i8]
%2 = alloca [30 x i8]
%3 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 0
%4 = call i32 @gets(i8* %3)
%5 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %0, %8
%9 = phi i64 [ %14, %8 ], [ 0, %0 ]
%10 = phi i8 [ %16, %8 ], [ %6, %0 ]
%11 = phi i32 [ %13, %8 ], [ 0, %0 ]
%12 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %9
store i8 %10, i8* %12
%13 = add nuw nsw i32 %11, 1
%14 = add nuw nsw i64 %9, 1
%15 = getelementptr inbounds [30 x i8], [30 x i8]* %1, i64 0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %18, label %8
18: ; preds = %8
%19 = and i64 %14, 4294967295
br label %20
20: ; preds = %18, %0
%21 = phi i64 [ 0, %0 ], [ %19, %18 ]
%22 = phi i32 [ 0, %0 ], [ %13, %18 ]
%23 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 %21
store i8 0, i8* %23
%24 = call i32 @puts(i8* %5)
%25 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %22)
ret i32 0
}