#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 EOF;
char getchar1();
char *gets1(char *);
int /*<<< orphan*/ printf(char *, ...);
int putchar1(int);
int puts1(char *);
int main() {
  printf("---- getchar1 ----\n");
  printf("Enter a character: ");
  char test = getchar1();
  printf("getchar1() returns %c\n\n", test);
  char test1[20];
  printf("---- gets1 ----\n");
  printf("Enter a string: ");
  printf("gets(test1) returns %s\n", gets1(test1));
  printf("test1 = %s\n\n", test1);
  char c = 'A';
  printf("---- putchar1 ----\n");
  printf(" <- putchar1('A') returns %d\n", putchar1(c));
  if (putchar1(-1) == EOF)
    printf("putchar(-1) returns EOF\n");
  else
    printf("putchar(-1) does NOT return EOF\n");
  printf("\n");
  char *s = "Phenomenal";
  printf("---- puts1 ----\n");
  printf(" <- puts1(\"Phenomenal\") returns %d\n", puts1(s));
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <getchar1@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%esi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1050 <gets1@plt>
mov    %rax,%rsi
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x41,-0x21(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x21(%rbp),%edi
call   1070 <putchar1@plt>
mov    %eax,%esi
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <putchar1@plt>
mov    0x2dcd(%rip),%rcx
cmp    (%rcx),%eax
jne    1236 <main+0xe6>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1244 <main+0xf4>
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe9a(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1040 <puts1@plt>
mov    %eax,%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
lea    0xf33(%rip),%rdi
call   1040 <puts@plt>
lea    0xe78(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
call   1080 <getchar1@plt>
movsbl %al,%esi
lea    0xe74(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf14(%rip),%rdi
call   1040 <puts@plt>
lea    0xe72(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1070 <gets1@plt>
lea    0xe6a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe71(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xedd(%rip),%rdi
call   1040 <puts@plt>
mov    $0x41,%edi
call   1090 <putchar1@plt>
lea    0xe57(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <putchar1@plt>
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%eax
lea    0xee7(%rip),%rax
lea    0xeb0(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xeb6(%rip),%rdi
call   1040 <puts@plt>
lea    0xe25(%rip),%rdi
call   1060 <puts1@plt>
lea    0xe24(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"---- getchar1 ----\0A\00"
@.str.1 = [20 x i8] c"Enter a character: \00"
@.str.2 = [24 x i8] c"getchar1() returns %c\0A\0A\00"
@.str.3 = [17 x i8] c"---- gets1 ----\0A\00"
@.str.4 = [17 x i8] c"Enter a string: \00"
@.str.5 = [24 x i8] c"gets(test1) returns %s\0A\00"
@.str.6 = [13 x i8] c"test1 = %s\0A\0A\00"
@.str.7 = [20 x i8] c"---- putchar1 ----\0A\00"
@.str.8 = [30 x i8] c" <- putchar1('A') returns %d\0A\00"
@EOF = global i32 0
@.str.9 = [25 x i8] c"putchar(-1) returns EOF\0A\00"
@.str.10 = [33 x i8] c"putchar(-1) does NOT return EOF\0A\00"
@.str.11 = [2 x i8] c"\0A\00"
@.str.12 = [11 x i8] c"Phenomenal\00"
@.str.13 = [17 x i8] c"---- puts1 ----\0A\00"
@.str.14 = [36 x i8] c" <- puts1(\22Phenomenal\22) returns %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [20 x i8]
%4 = alloca i8
%5 = alloca i8*
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%8 = call signext i8 (...) @getchar1()
store i8 %8, i8* %2
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%14 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%15 = call i8* @gets1(i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %17)
store i8 65, i8* %4
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = call i32 @putchar1(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %22)
%24 = call i32 @putchar1(i32 -1)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %29
27: ; preds = %0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.9, i64 0, i64 0))
br label %31
29: ; preds = %0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.10, i64 0, i64 0))
br label %31
31: ; preds = %29, %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0), i8** %5
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.13, i64 0, i64 0))
%34 = load i8*, i8** %5
%35 = call i32 @puts1(i8* %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0), i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"Enter a character: \00"
@.str.2 = [24 x i8] c"getchar1() returns %c\0A\0A\00"
@.str.4 = [17 x i8] c"Enter a string: \00"
@.str.5 = [24 x i8] c"gets(test1) returns %s\0A\00"
@.str.6 = [13 x i8] c"test1 = %s\0A\0A\00"
@.str.8 = [30 x i8] c" <- putchar1('A') returns %d\0A\00"
@EOF = global i32 0
@.str.12 = [11 x i8] c"Phenomenal\00"
@.str.14 = [36 x i8] c" <- puts1(\22Phenomenal\22) returns %d\0A\00"
@str = [19 x i8] c"---- getchar1 ----\00"
@str.15 = [16 x i8] c"---- gets1 ----\00"
@str.16 = [19 x i8] c"---- putchar1 ----\00"
@str.17 = [32 x i8] c"putchar(-1) does NOT return EOF\00"
@str.18 = [16 x i8] c"---- puts1 ----\00"
@str.19 = [24 x i8] c"putchar(-1) returns EOF\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call signext i8 (...) @getchar1()
%5 = sext i8 %4 to i32
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.15, i64 0, i64 0))
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%10 = call i8* @gets1(i8* %7)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %10)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %7)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.16, i64 0, i64 0))
%14 = call i32 @putchar1(i32 65)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.8, i64 0, i64 0), i32 %14)
%16 = call i32 @putchar1(i32 -1)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
%19 = select i1 %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @str.19, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @str.17, i64 0, i64 0)
%20 = call i32 @puts(i8* dereferenceable(1) %19)
%21 = call i32 @putchar(i32 10)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.18, i64 0, i64 0))
%23 = call i32 @puts1(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.12, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0), i32 %23)
%25 = call i32 @putchar(i32 10)
ret i32 0
}