#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 */
char *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ stdin;
int main() {
  char buf[256];
  char *ptr;
  ptr = fgets(buf, 100, stdin);
  printf("%d %s\n", ptr == buf, ptr);
  ptr = fgets(buf, 100, stdin);
  printf("%d %s\n", ptr == buf, ptr);
  buf[0] = 'a';
  ptr = fgets(buf, 100, stdin);
  printf("%d %d\n", ptr == 0, buf[0]);
  buf[0] = 'b';
  ptr = fgets(buf, 1, stdin);
  printf("%d %d\n", ptr == 0, buf[0]);
  buf[0] = 'c';
  ptr = fgets(buf, 100, stdin);
  printf("%d %d\n", ptr == 0, buf[0]);
  buf[0] = 'd';
  ptr = fgets(buf, 0, stdin);
  printf("%d %d\n", ptr == 0, buf[0]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
mov    0x2ea8(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1040 <fgets@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
lea    -0x110(%rbp),%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%esi
mov    -0x118(%rbp),%rdx
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1040 <fgets@plt>
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
lea    -0x110(%rbp),%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%esi
mov    -0x118(%rbp),%rdx
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x61,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1040 <fgets@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
movsbl -0x110(%rbp),%edx
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x62,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
mov    0x2db6(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1040 <fgets@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
movsbl -0x110(%rbp),%edx
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x63,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1040 <fgets@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
movsbl -0x110(%rbp),%edx
lea    0xd57(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movb   $0x64,-0x110(%rbp)
lea    -0x110(%rbp),%rdi
mov    0x2d1c(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fgets@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
movsbl -0x110(%rbp),%edx
lea    0xd0d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    0x2eb5(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
xor    %esi,%esi
cmp    %rbx,%rax
sete   %sil
lea    0xeaa(%rip),%r14
mov    %r14,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
xor    %esi,%esi
cmp    %rbx,%rax
sete   %sil
mov    %r14,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
movb   $0x61,(%rsp)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
xor    %esi,%esi
test   %rax,%rax
sete   %sil
movsbl (%rsp),%edx
lea    0xe56(%rip),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movb   $0x62,(%rsp)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1040 <fgets@plt>
xor    %esi,%esi
test   %rax,%rax
sete   %sil
movsbl (%rsp),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movb   $0x63,(%rsp)
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
xor    %esi,%esi
test   %rax,%rax
sete   %sil
movsbl (%rsp),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
movb   $0x64,(%rsp)
mov    (%r15),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <fgets@plt>
xor    %esi,%esi
test   %rax,%rax
sete   %sil
movsbl (%rsp),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [7 x i8] c"%d %s\0A\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i8*
store i32 0, i32* %1
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i8* @fgets(i8* %4, i32 100, i32 %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%9 = icmp eq i8* %7, %8
%10 = zext i1 %9 to i32
%11 = load i8*, i8** %3
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i8* @fgets(i8* %13, i32 100, i32 %14)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%18 = icmp eq i8* %16, %17
%19 = zext i1 %18 to i32
%20 = load i8*, i8** %3
%21 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %19, i8* %20)
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8 97, i8* %22
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%24 = load i32, i32* @stdin
%25 = call i8* @fgets(i8* %23, i32 100, i32 %24)
store i8* %25, i8** %3
%26 = load i8*, i8** %3
%27 = icmp eq i8* %26, null
%28 = zext i1 %27 to i32
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %28, i32 %31)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8 98, i8* %33
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%35 = load i32, i32* @stdin
%36 = call i8* @fgets(i8* %34, i32 1, i32 %35)
store i8* %36, i8** %3
%37 = load i8*, i8** %3
%38 = icmp eq i8* %37, null
%39 = zext i1 %38 to i32
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %42)
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8 99, i8* %44
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%46 = load i32, i32* @stdin
%47 = call i8* @fgets(i8* %45, i32 100, i32 %46)
store i8* %47, i8** %3
%48 = load i8*, i8** %3
%49 = icmp eq i8* %48, null
%50 = zext i1 %49 to i32
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %50, i32 %53)
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store i8 100, i8* %55
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%57 = load i32, i32* @stdin
%58 = call i8* @fgets(i8* %56, i32 0, i32 %57)
store i8* %58, i8** %3
%59 = load i8*, i8** %3
%60 = icmp eq i8* %59, null
%61 = zext i1 %60 to i32
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %61, i32 %64)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [7 x i8] c"%d %s\0A\00"
@.str.1 = [7 x i8] c"%d %d\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i8* @fgets(i8* %2, i32 100, i32 %3)
%5 = icmp eq i8* %4, %2
%6 = zext i1 %5 to i32
%7 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6, i8* %4)
%8 = load i32, i32* @stdin
%9 = call i8* @fgets(i8* %2, i32 100, i32 %8)
%10 = icmp eq i8* %9, %2
%11 = zext i1 %10 to i32
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %11, i8* %9)
store i8 97, i8* %2
%13 = load i32, i32* @stdin
%14 = call i8* @fgets(i8* %2, i32 100, i32 %13)
%15 = icmp eq i8* %14, null
%16 = zext i1 %15 to i32
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %18)
store i8 98, i8* %2
%20 = load i32, i32* @stdin
%21 = call i8* @fgets(i8* %2, i32 1, i32 %20)
%22 = icmp eq i8* %21, null
%23 = zext i1 %22 to i32
%24 = load i8, i8* %2
%25 = sext i8 %24 to i32
%26 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %25)
store i8 99, i8* %2
%27 = load i32, i32* @stdin
%28 = call i8* @fgets(i8* %2, i32 100, i32 %27)
%29 = icmp eq i8* %28, null
%30 = zext i1 %29 to i32
%31 = load i8, i8* %2
%32 = sext i8 %31 to i32
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %32)
store i8 100, i8* %2
%34 = load i32, i32* @stdin
%35 = call i8* @fgets(i8* %2, i32 0, i32 %34)
%36 = icmp eq i8* %35, null
%37 = zext i1 %36 to i32
%38 = load i8, i8* %2
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 %39)
ret i32 0
}