#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*/ FILE;

/* Variables and functions */
int EOF;
int errno;
int ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int read_option(FILE *cfg_file, const char *name, int *value) {
  int result;
  char scan_format[20] = {0};
  sprintf(scan_format, "%s=%%d\n", name);
  result = fscanf(cfg_file, scan_format, value);
  if (result != 1) {
    fprintf(stderr, "Can't read %s value", name);
    if (result == EOF) {
      int stream_err = ferror(cfg_file);
      if (stream_err != 0)
        fprintf(stderr, ", error: %d (%s)", errno, strerror(errno));
      else
        fprintf(stderr, ", result: %d (Reached end of input)", result);
    }
    fprintf(stderr, "\n");
  }
  return result;
}


x86 assembly (clang, -O0):
<read_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe6d(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
je     1271 <read_option+0x111>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
mov    0x2e0d(%rip),%rcx
cmp    (%rcx),%eax
jne    125a <read_option+0xfa>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     123b <read_option+0xdb>
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%edx
mov    %rax,%rcx
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1255 <read_option+0xf5>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    125a <read_option+0xfa>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_option>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%rbp
mov    %rsi,%r15
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
lea    0xe85(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r15,%rdx
call   1060 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
je     1226 <read_option+0xd6>
mov    0x2e2f(%rip),%r12
mov    (%r12),%edi
lea    0xe54(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2e23(%rip),%rax
cmp    (%rax),%ebp
jne    1214 <read_option+0xc4>
mov    %r14,%rdi
call   1030 <ferror@plt>
mov    (%r12),%r14d
test   %eax,%eax
je     1201 <read_option+0xb1>
mov    0x2df0(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   1070 <strerror@plt>
lea    0xe2c(%rip),%rsi
mov    %r14d,%edi
mov    %ebx,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1214 <read_option+0xc4>
lea    0xe25(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r12),%edi
lea    0xde7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s=%%d\0A\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Can't read %s value\00"
@EOF = global i32 0
@.str.2 = [17 x i8] c", error: %d (%s)\00"
@errno = global i32 0
@.str.3 = [36 x i8] c", result: %d (Reached end of input)\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @read_option(i32* %0, i8* %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca [20 x i8]
%9 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
%10 = bitcast [20 x i8]* %8 to i8*
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%12 = load i8*, i8** %5
%13 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32*, i32** %4
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i32 @fscanf(i32* %14, i8* %15, i32* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %46
20: ; preds = %3
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %5
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i32, i32* %7
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %43
27: ; preds = %20
%28 = load i32*, i32** %4
%29 = call i32 @ferror(i32* %28)
store i32 %29, i32* %9
%30 = load i32, i32* %9
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %34, i8* %36)
br label %42
38: ; preds = %27
%39 = load i32, i32* @stderr
%40 = load i32, i32* %7
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %38, %32
br label %43
43: ; preds = %42, %20
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %46
46: ; preds = %43, %3
%47 = load i32, i32* %7
ret i32 %47
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s=%%d\0A\00"
@stderr = global i32 0
@.str.1 = [20 x i8] c"Can't read %s value\00"
@EOF = global i32 0
@.str.2 = [17 x i8] c", error: %d (%s)\00"
@errno = global i32 0
@.str.3 = [36 x i8] c", result: %d (Reached end of input)\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @read_option(i32* nocapture %0, i8* %1, i32* %2) {
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = call i32 @fscanf(i32* %0, i8* %5, i32* %2)
%8 = icmp eq i32 %7, 1
br i1 %8, label %27, label %9
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %7, %12
br i1 %13, label %14, label %24
14: ; preds = %9
%15 = tail call i32 @ferror(i32* %0)
%16 = icmp eq i32 %15, 0
%17 = load i32, i32* @stderr
br i1 %16, label %22, label %18
18: ; preds = %14
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %20)
br label %24
22: ; preds = %14
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i32 %7)
br label %24
24: ; preds = %18, %22, %9
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %27
27: ; preds = %24, %3
ret i32 %7
}