#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ fatal(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ stdin;
const char *read_share(void *data, int number, int threshold, size_t size) {
  (void)size;
  static char buffer[(128 + 1 + 10 + 1 + 1024 / 4 + 10)];
  bool opt_quiet = *((bool *)data);
  if (!opt_quiet) {
    printf("Enter share [%d/%d]: ", number, threshold);
  }
  if (!fgets(buffer, sizeof(buffer), stdin)) {
    fatal("I/O error while reading shares");
    return NULL;
  }
  return buffer;
}


x86 assembly (clang, -O0):
<read_share>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    116b <read_share+0x3b>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edx
lea    0x2ed5(%rip),%rdi
mov    $0x196,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    11a7 <read_share+0x77>
lea    0xe81(%rip),%rdi
call   1050 <fatal@plt>
movq   $0x0,-0x8(%rbp)
jmp    11b2 <read_share+0x82>
lea    0x2ea2(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_share>:
push   %rbx
cmpl   $0x0,(%rdi)
jne    1142 <read_share+0x12>
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
lea    0x2efe(%rip),%rbx
mov    %rbx,%rdi
mov    $0x196,%esi
call   1040 <fgets@plt>
test   %eax,%eax
jne    1171 <read_share+0x41>
lea    0xeac(%rip),%rdi
call   1050 <fatal@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@read_share.buffer = internal global [406 x i8] zeroinitializer
@.str = [22 x i8] c"Enter share [%d/%d]: \00"
@stdin = global i32 0
@.str.1 = [31 x i8] c"I/O error while reading shares\00"
define i8* @read_share(i8* %0, i32 %1, i32 %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i64 %3, i64* %9
%11 = load i64, i64* %9
%12 = load i8*, i8** %6
%13 = bitcast i8* %12 to i32*
%14 = load i32, i32* %13
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %4
%18 = load i32, i32* %7
%19 = load i32, i32* %8
%20 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %19)
br label %21
21: ; preds = %17, %4
%22 = load i32, i32* @stdin
%23 = call i32 @fgets(i8* getelementptr inbounds ([406 x i8], [406 x i8]* @read_share.buffer, i64 0, i64 0), i32 406, i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = call i32 @fatal(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %5
br label %28
27: ; preds = %21
store i8* getelementptr inbounds ([406 x i8], [406 x i8]* @read_share.buffer, i64 0, i64 0), i8** %5
br label %28
28: ; preds = %27, %25
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
@read_share.buffer = internal global [406 x i8] zeroinitializer
@.str = [22 x i8] c"Enter share [%d/%d]: \00"
@stdin = global i32 0
@.str.1 = [31 x i8] c"I/O error while reading shares\00"
define i8* @read_share(i8* nocapture %0, i32 %1, i32 %2, i64 %3) {
%5 = bitcast i8* %0 to i32*
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
br label %10
10: ; preds = %8, %4
%11 = load i32, i32* @stdin
%12 = tail call i32 @fgets(i8* getelementptr inbounds ([406 x i8], [406 x i8]* @read_share.buffer, i64 0, i64 0), i32 406, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @fatal(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %10, %14
%17 = phi i8* [ null, %14 ], [ getelementptr inbounds ([406 x i8], [406 x i8]* @read_share.buffer, i64 0, i64 0), %10 ]
ret i8* %17
}