#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  char buff[255];
  char *name;
  char *id;
  printf("Enter a string (up to 24 chars): ");
  fgets(buff, 25, stdin);
  buff[strlen(buff) - 1] = '\0';
  name = (char *)malloc(strlen(buff) + 1);
  strcpy(name, buff);
  printf("\nEnter another string (up to 4 chars): ");
  fgets(buff, 5, stdin);
  id = (char *)malloc(strlen(buff) + 1);
  strcpy(id, buff);
  printf("\nstring 1: %s\nstring 2: %s\n", name, id);
  free(name);
  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)
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
mov    $0x19,%esi
call   1070 <fgets@plt>
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x110(%rbp,%rax,1)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1040 <strcpy@plt>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2de2(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1070 <fgets@plt>
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x118(%rbp),%rsi
mov    -0x120(%rbp),%rdx
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x118(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e67(%rip),%rbx
mov    (%rbx),%edx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x19,%esi
call   1070 <fgets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%edx
mov    %r14,%rdi
mov    $0x5,%esi
call   1070 <fgets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xe47(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Enter a string (up to 24 chars): \00"
@stdin = global i32 0
@.str.1 = [40 x i8] c"\0AEnter another string (up to 4 chars): \00"
@.str.2 = [28 x i8] c"\0Astring 1: %s\0Astring 2: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [255 x i8]
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i32 @fgets(i8* %10, i32 25, i32 %11)
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 %16
store i8 0, i8* %17
%18 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, 1
%21 = call i64 @malloc(i32 %20)
%22 = inttoptr i64 %21 to i8*
store i8* %22, i8** %7
%23 = load i8*, i8** %7
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%25 = call i32 @strcpy(i8* %23, i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%27 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* %27, i32 5, i32 %28)
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
%32 = add nsw i32 %31, 1
%33 = call i64 @malloc(i32 %32)
%34 = inttoptr i64 %33 to i8*
store i8* %34, i8** %8
%35 = load i8*, i8** %8
%36 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%37 = call i32 @strcpy(i8* %35, i8* %36)
%38 = load i8*, i8** %7
%39 = load i8*, i8** %8
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %38, i8* %39)
%41 = load i8*, i8** %7
%42 = call i32 @free(i8* %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [34 x i8] c"Enter a string (up to 24 chars): \00"
@stdin = global i32 0
@.str.1 = [40 x i8] c"\0AEnter another string (up to 4 chars): \00"
@.str.2 = [28 x i8] c"\0Astring 1: %s\0Astring 2: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, 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))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 25, i32 %6)
%8 = call i32 @strlen(i8* %4)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @strlen(i8* %4)
%13 = add nsw i32 %12, 1
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = call i32 @strcpy(i8* %15, i8* %4)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %4, i32 5, i32 %18)
%20 = call i32 @strlen(i8* %4)
%21 = add nsw i32 %20, 1
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = call i32 @strcpy(i8* %23, i8* %4)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %15, i8* %23)
%26 = call i32 @free(i8* %15)
ret i32 0
}