#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int i = 0, j = 0, k = 0;
  char *a, *b, *c;
  a = (char *)malloc(100);
  b = (char *)malloc(100);
  printf("Digite a primeira string:");
  scanf("%s", a);
  printf("Digite a segunda string:");
  scanf("%s", b);
  c = (char *)malloc(strlen(a) + strlen(b));
  while (i < (strlen(a) + strlen(b))) {
    if (j < strlen(a)) {
      c[i] = a[j];
      i += 1;
      j += 1;
    }
    if (k < strlen(b)) {
      c[i] = b[k];
      i += 1;
      k += 1;
    }
  }
  c[i] = '\0';
  printf("%s\n", c);
  free(a);
  free(b);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe6a(%rip),%rdi
call   1070 <scanf@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
add    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%ecx
mov    %eax,%edx
mov    -0x40(%rbp),%eax
add    %edx,%ecx
cmp    %ecx,%eax
jge    12b0 <main+0x160>
mov    -0x18(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%eax
cmp    %ecx,%eax
jge    1267 <main+0x117>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
jge    12ab <main+0x15b>
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f6 <main+0xa6>
mov    -0x38(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x38(%rbp),%rsi
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
lea    0xe74(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe7e(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <scanf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
add    %eax,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,(%rsp)
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
add    %ebp,%eax
jle    1266 <main+0x106>
xor    %ebx,%ebx
xor    %r13d,%r13d
xor    %r15d,%r15d
jmp    1218 <main+0xb8>
nop
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1050 <strlen@plt>
add    %ebp,%eax
cmp    %eax,%ebx
jge    1266 <main+0x106>
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    %eax,%r13d
jge    123e <main+0xde>
movslq %r13d,%rax
movzbl (%r14,%rax,1),%eax
movslq %ebx,%rbx
mov    (%rsp),%rcx
mov    %al,(%rcx,%rbx,1)
add    $0x1,%ebx
add    $0x1,%r13d
mov    %r12,%rdi
call   1050 <strlen@plt>
cmp    %eax,%r15d
jge    1200 <main+0xa0>
movslq %r15d,%rax
movzbl (%r12,%rax,1),%eax
movslq %ebx,%rbx
mov    (%rsp),%rcx
mov    %al,(%rcx,%rbx,1)
add    $0x1,%ebx
add    $0x1,%r15d
jmp    1200 <main+0xa0>
movslq %ebx,%rax
mov    (%rsp),%rdi
movb   $0x0,(%rdi,%rax,1)
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Digite a primeira string:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [25 x i8] c"Digite a segunda string:\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%12 = call i64 @malloc(i32 100)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %9
%14 = call i64 @malloc(i32 100)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %10
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %9
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%20 = load i8*, i8** %10
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %9
%23 = call i32 @strlen(i8* %22)
%24 = load i8*, i8** %10
%25 = call i32 @strlen(i8* %24)
%26 = add nsw i32 %23, %25
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %11
br label %29
29: ; preds = %75, %2
%30 = load i32, i32* %6
%31 = load i8*, i8** %9
%32 = call i32 @strlen(i8* %31)
%33 = load i8*, i8** %10
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %32, %34
%36 = icmp slt i32 %30, %35
br i1 %36, label %37, label %76
37: ; preds = %29
%38 = load i32, i32* %7
%39 = load i8*, i8** %9
%40 = call i32 @strlen(i8* %39)
%41 = icmp slt i32 %38, %40
br i1 %41, label %42, label %56
42: ; preds = %37
%43 = load i8*, i8** %9
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
%47 = load i8, i8* %46
%48 = load i8*, i8** %11
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
store i8 %47, i8* %51
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
%54 = load i32, i32* %7
%55 = add nsw i32 %54, 1
store i32 %55, i32* %7
br label %56
56: ; preds = %42, %37
%57 = load i32, i32* %8
%58 = load i8*, i8** %10
%59 = call i32 @strlen(i8* %58)
%60 = icmp slt i32 %57, %59
br i1 %60, label %61, label %75
61: ; preds = %56
%62 = load i8*, i8** %10
%63 = load i32, i32* %8
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
%66 = load i8, i8* %65
%67 = load i8*, i8** %11
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %67, i64 %69
store i8 %66, i8* %70
%71 = load i32, i32* %6
%72 = add nsw i32 %71, 1
store i32 %72, i32* %6
%73 = load i32, i32* %8
%74 = add nsw i32 %73, 1
store i32 %74, i32* %8
br label %75
75: ; preds = %61, %56
br label %29
76: ; preds = %29
%77 = load i8*, i8** %11
%78 = load i32, i32* %6
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
store i8 0, i8* %80
%81 = load i8*, i8** %11
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %81)
%83 = load i8*, i8** %9
%84 = call i32 @free(i8* %83)
%85 = load i8*, i8** %10
%86 = call i32 @free(i8* %85)
ret i32 0
}

LLVM IR (-O2):
@.str = [26 x i8] c"Digite a primeira string:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [25 x i8] c"Digite a segunda string:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 100)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i64 @malloc(i32 100)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = tail call i32 @strlen(i8* %4)
%12 = tail call i32 @strlen(i8* %6)
%13 = add nsw i32 %12, %11
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 @strlen(i8* %4)
%17 = tail call i32 @strlen(i8* %6)
%18 = add nsw i32 %17, %16
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %54
20: ; preds = %2, %47
%21 = phi i32 [ %49, %47 ], [ 0, %2 ]
%22 = phi i32 [ %35, %47 ], [ 0, %2 ]
%23 = phi i32 [ %48, %47 ], [ 0, %2 ]
%24 = tail call i32 @strlen(i8* %4)
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %34
26: ; preds = %20
%27 = sext i32 %22 to i64
%28 = getelementptr inbounds i8, i8* %4, i64 %27
%29 = load i8, i8* %28
%30 = sext i32 %21 to i64
%31 = getelementptr inbounds i8, i8* %15, i64 %30
store i8 %29, i8* %31
%32 = add nsw i32 %21, 1
%33 = add nsw i32 %22, 1
br label %34
34: ; preds = %26, %20
%35 = phi i32 [ %33, %26 ], [ %22, %20 ]
%36 = phi i32 [ %32, %26 ], [ %21, %20 ]
%37 = tail call i32 @strlen(i8* %6)
%38 = icmp slt i32 %23, %37
br i1 %38, label %39, label %47
39: ; preds = %34
%40 = sext i32 %23 to i64
%41 = getelementptr inbounds i8, i8* %6, i64 %40
%42 = load i8, i8* %41
%43 = sext i32 %36 to i64
%44 = getelementptr inbounds i8, i8* %15, i64 %43
store i8 %42, i8* %44
%45 = add nsw i32 %36, 1
%46 = add nsw i32 %23, 1
br label %47
47: ; preds = %39, %34
%48 = phi i32 [ %46, %39 ], [ %23, %34 ]
%49 = phi i32 [ %45, %39 ], [ %36, %34 ]
%50 = tail call i32 @strlen(i8* %4)
%51 = tail call i32 @strlen(i8* %6)
%52 = add nsw i32 %51, %50
%53 = icmp slt i32 %49, %52
br i1 %53, label %20, label %54
54: ; preds = %47, %2
%55 = phi i32 [ 0, %2 ], [ %49, %47 ]
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %15, i64 %56
store i8 0, i8* %57
%58 = tail call i32 @puts(i8* dereferenceable(1) %15)
%59 = tail call i32 @free(i8* %4)
%60 = tail call i32 @free(i8* %6)
ret i32 0
}