#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*/ EXIT_FAILURE;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
void print_message() {
  char *line = NULL;
  size_t line_size = 0;
  fputs("Give the number of times you want to write the line: ", stdout);
  if (!getline(&line, &line_size, stdin)) {
    fputs("error: failed to read the number\n", stderr);
    exit(EXIT_FAILURE);
  }
  int n = atoi(line);
  fputs("Write the line to print: ", stdout);
  if (!getline(&line, &line_size, stdin)) {
    fputs("error: failed to read the message\n", stderr);
    exit(EXIT_FAILURE);
  }
  for (int i = 0; i < n; i++)
    fprintf(stdout, "%s", line);
  free(line);
}


x86 assembly (clang, -O0):
<print_message>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <getline@plt>
cmp    $0x0,%eax
jne    11cf <print_message+0x6f>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
lea    0xe7a(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
lea    0xe6d(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <getline@plt>
cmp    $0x0,%eax
jne    1232 <print_message+0xd2>
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
lea    0xe53(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    126c <print_message+0x10c>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1239 <print_message+0xd9>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_message>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e47(%rip),%r15
mov    (%r15),%esi
lea    0xe75(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2e51(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1070 <getline@plt>
test   %eax,%eax
je     1217 <print_message+0xb7>
mov    (%rsp),%rdi
call   1060 <atoi@plt>
mov    %eax,%ebx
mov    (%r15),%esi
lea    0xe98(%rip),%rdi
call   1040 <fputs@plt>
mov    (%r14),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1070 <getline@plt>
test   %eax,%eax
je     1229 <print_message+0xc9>
test   %ebx,%ebx
jle    1204 <print_message+0xa4>
lea    0xeb1(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%edi
mov    (%rsp),%rdx
mov    %r14,%rsi
call   1050 <fprintf@plt>
add    $0xffffffff,%ebx
jne    11f0 <print_message+0x90>
mov    (%rsp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dba(%rip),%rax
mov    (%rax),%esi
lea    0xe0f(%rip),%rdi
jmp    1239 <print_message+0xd9>
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
lea    0xe39(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"Give the number of times you want to write the line: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [34 x i8] c"error: failed to read the number\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [26 x i8] c"Write the line to print: \00"
@.str.3 = [35 x i8] c"error: failed to read the message\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define void @print_message() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
store i8* null, i8** %1
store i64 0, i64* %2
%5 = load i32, i32* @stdout
%6 = call i32 @fputs(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @stdin
%8 = call i32 @getline(i8** %1, i64* %2, i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = load i8*, i8** %1
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %3
%18 = load i32, i32* @stdout
%19 = call i32 @fputs(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @stdin
%21 = call i32 @getline(i8** %1, i64* %2, i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %15
%24 = load i32, i32* @stderr
%25 = call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %15
store i32 0, i32* %4
br label %29
29: ; preds = %37, %28
%30 = load i32, i32* %4
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %40
33: ; preds = %29
%34 = load i32, i32* @stdout
%35 = load i8*, i8** %1
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %33
%38 = load i32, i32* %4
%39 = add nsw i32 %38, 1
store i32 %39, i32* %4
br label %29
40: ; preds = %29
%41 = load i8*, i8** %1
%42 = call i32 @free(i8* %41)
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"Give the number of times you want to write the line: \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.1 = [34 x i8] c"error: failed to read the number\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [26 x i8] c"Write the line to print: \00"
@.str.3 = [35 x i8] c"error: failed to read the message\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define void @print_message() {
%1 = alloca i8*
%2 = alloca i64
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = load i32, i32* @stdout
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @stdin
%8 = call i32 @getline(i8** %1, i64* %2, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fputs(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = load i8*, i8** %1
%17 = call i32 @atoi(i8* %16)
%18 = load i32, i32* @stdout
%19 = call i32 @fputs(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i32, i32* @stdin
%21 = call i32 @getline(i8** %1, i64* %2, i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %15
%24 = icmp sgt i32 %17, 0
br i1 %24, label %33, label %30
25: ; preds = %15
%26 = load i32, i32* @stderr
%27 = call i32 @fputs(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %33, %23
%31 = load i8*, i8** %1
%32 = call i32 @free(i8* %31)
ret void
33: ; preds = %23, %33
%34 = phi i32 [ %38, %33 ], [ 0, %23 ]
%35 = load i32, i32* @stdout
%36 = load i8*, i8** %1
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %36)
%38 = add nuw nsw i32 %34, 1
%39 = icmp eq i32 %38, %17
br i1 %39, label %30, label %33
}