#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 EXIT_FAILURE;
int atoi(int /*<<< orphan*/);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ roundc(int /*<<< orphan*/ *, int, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int opt = 0, c = 0, f = 0, n = 1;
  FILE *stream = stdin;
  while ((opt = getopt(argc, argv, "hcfn:")) != -1) {
    switch (opt) {
    case 'h':
      fprintf(stdout,
              "numround - A program that rounds off numbers it "
              "encounter.\nSynopsis : numround [-hcfn] <FILE> or "
              "STDIN\nOptions available :  \n\t-c Force the number to be "
              "rounded up. Ceiling.\n\t-f  Force the number to be rounded "
              "down. Floor.\n\t-n <n>  Round numbers to the nearest factor of "
              "<n>.\n\t-h  Help: You're looking at it.\nYou can consult the "
              "man page for further information.\n");
      return 0;
      break;
    case 'c':
      c = 1;
      break;
    case 'f':
      f = 1;
      break;
    case 'n':
      n = atoi(optarg);
      break;
    default:
      fprintf(stderr, "invalid option \n");
      return EXIT_FAILURE;
      break;
    }
  }
  if (argc > optind) {
    if (!(stream = fopen(argv[optind], "r"))) {
      perror("num-utils-ng");
      return EXIT_FAILURE;
    }
  }
  roundc(stream, c, f, n);
  if (argc > optind) {
    if (fclose(stream) != 0) {
      perror("num-utils-ng");
      return EXIT_FAILURE;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe72(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1272 <main+0x102>
mov    -0x14(%rbp),%eax
add    $0xffffff9d,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xb,%eax
ja     1247 <main+0xd7>
mov    -0x30(%rbp),%rax
lea    0xe11(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <main+0x1c2>
movl   $0x1,-0x18(%rbp)
jmp    126d <main+0xfd>
movl   $0x1,-0x1c(%rbp)
jmp    126d <main+0xfd>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x20(%rbp)
jmp    126d <main+0xfd>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xf4a(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1332 <main+0x1c2>
jmp    11b0 <main+0x40>
mov    -0x8(%rbp),%eax
mov    0x2d5c(%rip),%rcx
cmp    (%rcx),%eax
jle    12d2 <main+0x162>
mov    -0x10(%rbp),%rax
mov    0x2d49(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xf15(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    12cd <main+0x15d>
lea    0xefd(%rip),%rdi
call   1070 <perror@plt>
mov    0x2cfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1332 <main+0x1c2>
jmp    12d2 <main+0x162>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
call   1040 <roundc@plt>
mov    -0x8(%rbp),%eax
mov    0x2cea(%rip),%rcx
cmp    (%rcx),%eax
jle    132b <main+0x1bb>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
cmp    $0x0,%rax
je     1326 <main+0x1b6>
lea    0xea4(%rip),%rdi
call   1070 <perror@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1332 <main+0x1c2>
jmp    132b <main+0x1bb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2e56(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
mov    $0x1,%r13d
movl   $0x0,0xc(%rsp)
lea    0xe59(%rip),%r15
mov    0x2e4a(%rip),%r14
xor    %r12d,%r12d
jmp    11cb <main+0x5b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r14),%edi
call   1090 <atoi@plt>
mov    %eax,%r13d
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    $0x6e,%eax
je     11c0 <main+0x50>
cmp    $0x65,%eax
jg     11fa <main+0x8a>
cmp    $0xffffffff,%eax
je     1225 <main+0xb5>
cmp    $0x63,%eax
jne    1285 <main+0x115>
movl   $0x1,0xc(%rsp)
jmp    11cb <main+0x5b>
cmp    $0x66,%eax
jne    1207 <main+0x97>
mov    $0x1,%r12d
jmp    11cb <main+0x5b>
cmp    $0x68,%eax
jne    1285 <main+0x115>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
call   1050 <fprintf@plt>
xor    %ebp,%ebp
jmp    12a3 <main+0x133>
mov    0x2dac(%rip),%r14
movslq (%r14),%rax
cmp    %ebx,%eax
mov    0x10(%rsp),%r15
jge    1251 <main+0xe1>
mov    0x0(%rbp,%rax,8),%rdi
lea    0xf3e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     1277 <main+0x107>
mov    %r15,%rdi
mov    0xc(%rsp),%esi
mov    %r12d,%edx
mov    %r13d,%ecx
call   1040 <roundc@plt>
xor    %ebp,%ebp
cmp    %ebx,(%r14)
jge    12a3 <main+0x133>
mov    %r15,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
je     12a3 <main+0x133>
lea    0xf06(%rip),%rdi
call   1070 <perror@plt>
jmp    129a <main+0x12a>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
lea    0xedc(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d1f(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32* null
@.str = [6 x i8] c"hcfn:\00"
@stdout = global i32 0
@.str.1 = [363 x i8] c"numround - A program that rounds off numbers it encounter.\0ASynopsis : numround [-hcfn] <FILE> or STDIN\0AOptions available : \0A\09-c Force the number to be rounded up. Ceiling.\0A\09-f Force the number to be rounded down. Floor.\0A\09-n <n> Round numbers to the nearest factor of <n>.\0A\09-h Help: You're looking at it.\0AYou can consult the man page for further information.\0A\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.2 = [17 x i8] c"invalid option \0A\00"
@EXIT_FAILURE = global i32 0
@optind = global i32 0
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [13 x i8] c"num-utils-ng\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 1, i32* %9
%11 = load i32*, i32** @stdin
store i32* %11, i32** %10
br label %12
12: ; preds = %31, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %32
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %27 [
i32 104, label %19
i32 99, label %22
i32 102, label %23
i32 110, label %24
]
19: ; preds = %17
%20 = load i32, i32* @stdout
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([363 x i8], [363 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %66
22: ; preds = %17
store i32 1, i32* %7
br label %31
23: ; preds = %17
store i32 1, i32* %8
br label %31
24: ; preds = %17
%25 = load i32, i32* @optarg
%26 = call i32 @atoi(i32 %25)
store i32 %26, i32* %9
br label %31
27: ; preds = %17
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %66
31: ; preds = %24, %23, %22
br label %12
32: ; preds = %12
%33 = load i32, i32* %4
%34 = load i32, i32* @optind
%35 = icmp sgt i32 %33, %34
br i1 %35, label %36, label %48
36: ; preds = %32
%37 = load i8**, i8*** %5
%38 = load i32, i32* @optind
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %42, i32** %10
%43 = icmp ne i32* %42, null
br i1 %43, label %47, label %44
44: ; preds = %36
%45 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
store i32 %46, i32* %3
br label %66
47: ; preds = %36
br label %48
48: ; preds = %47, %32
%49 = load i32*, i32** %10
%50 = load i32, i32* %7
%51 = load i32, i32* %8
%52 = load i32, i32* %9
%53 = call i32 @roundc(i32* %49, i32 %50, i32 %51, i32 %52)
%54 = load i32, i32* %4
%55 = load i32, i32* @optind
%56 = icmp sgt i32 %54, %55
br i1 %56, label %57, label %65
57: ; preds = %48
%58 = load i32*, i32** %10
%59 = call i64 @fclose(i32* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %57
%62 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
store i32 %63, i32* %3
br label %66
64: ; preds = %57
br label %65
65: ; preds = %64, %48
store i32 0, i32* %3
br label %66
66: ; preds = %65, %61, %44, %27, %19
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [6 x i8] c"hcfn:\00"
@stdout = global i32 0
@.str.1 = [363 x i8] c"numround - A program that rounds off numbers it encounter.\0ASynopsis : numround [-hcfn] <FILE> or STDIN\0AOptions available : \0A\09-c Force the number to be rounded up. Ceiling.\0A\09-f Force the number to be rounded down. Floor.\0A\09-n <n> Round numbers to the nearest factor of <n>.\0A\09-h Help: You're looking at it.\0AYou can consult the man page for further information.\0A\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.2 = [17 x i8] c"invalid option \0A\00"
@EXIT_FAILURE = global i32 0
@optind = global i32 0
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [13 x i8] c"num-utils-ng\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i32*, i32** @stdin
br label %4
4: ; preds = %11, %2
%5 = phi i32 [ 0, %2 ], [ 1, %11 ]
%6 = phi i32 [ 0, %2 ], [ %9, %11 ]
%7 = phi i32 [ 1, %2 ], [ %12, %11 ]
br label %8
8: ; preds = %11, %4
%9 = phi i32 [ %6, %4 ], [ 1, %11 ]
%10 = phi i32 [ %7, %4 ], [ %12, %11 ]
br label %11
11: ; preds = %8, %17
%12 = phi i32 [ %19, %17 ], [ %10, %8 ]
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
switch i32 %13, label %20 [
i32 -1, label %24
i32 104, label %14
i32 99, label %4
i32 102, label %8
i32 110, label %17
]
14: ; preds = %11
%15 = load i32, i32* @stdout
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([363 x i8], [363 x i8]* @.str.1, i64 0, i64 0))
br label %47
17: ; preds = %11
%18 = load i32, i32* @optarg
%19 = tail call i32 @atoi(i32 %18)
br label %11
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
br label %47
24: ; preds = %11
%25 = load i32, i32* @optind
%26 = icmp slt i32 %25, %0
br i1 %26, label %27, label %36
27: ; preds = %24
%28 = sext i32 %25 to i64
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i8*, i8** %29
%31 = tail call i32* @fopen(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
br label %47
36: ; preds = %27, %24
%37 = phi i32* [ %31, %27 ], [ %3, %24 ]
%38 = tail call i32 @roundc(i32* %37, i32 %5, i32 %9, i32 %12)
%39 = load i32, i32* @optind
%40 = icmp slt i32 %39, %0
br i1 %40, label %41, label %47
41: ; preds = %36
%42 = tail call i64 @fclose(i32* %37)
%43 = icmp eq i64 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %41
%45 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
br label %47
47: ; preds = %36, %41, %44, %33, %20, %14
%48 = phi i32 [ %23, %20 ], [ 0, %14 ], [ %46, %44 ], [ %35, %33 ], [ 0, %41 ], [ 0, %36 ]
ret i32 %48
}