#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 */
scalar_t__ EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, ...);
scalar_t__ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(int);
int main(int argc, char *argv[]) {
  FILE *fp;
  char buf[516];
  char *input_file = "/etc/group";
  if ((fp = fopen(input_file, "r")) == NULL) {
    fprintf(stderr, "Err(%d) %s: %s\n", errno, strerror(errno), input_file);
    exit(EXIT_FAILURE);
  }
  while ((fgets(buf, 516, fp)) != NULL) {
    if (fputs(buf, stdout) == EOF) {
      fprintf(stderr, "Err(%d) %s: fputs()\n", errno, strerror(errno));
      exit(EXIT_FAILURE);
    }
  }
  fclose(fp);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe70(%rip),%rax
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1216 <main+0xa6>
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x230(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x22c(%rbp)
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x230(%rbp),%edi
mov    -0x22c(%rbp),%edx
mov    %rax,%rcx
mov    -0x228(%rbp),%r8
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    121b <main+0xab>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x204,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12bb <main+0x14b>
lea    -0x220(%rbp),%rdi
mov    0x2d78(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2d92(%rip),%rcx
cmp    (%rcx),%rax
jne    12b6 <main+0x146>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x238(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x234(%rbp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x238(%rbp),%edi
mov    -0x234(%rbp),%edx
mov    %rax,%rcx
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    121b <main+0xab>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2ced(%rip),%rax
mov    (%rax),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
lea    0xe7c(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1231 <main+0xc1>
mov    %rax,%r14
mov    %rsp,%rbx
mov    0x2e1a(%rip),%r15
mov    0x2e3b(%rip),%rbp
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x204,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1212 <main+0xa2>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1040 <fputs@plt>
cmp    0x0(%rbp),%rax
jne    11b0 <main+0x40>
mov    0x2dfb(%rip),%rax
mov    (%rax),%ebx
mov    0x2dea(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xe27(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da0(%rip),%rax
mov    (%rax),%ebx
mov    0x2d8f(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1090 <strerror@plt>
lea    0xdbc(%rip),%rsi
lea    0xda8(%rip),%r8
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1204 <main+0x94>

LLVM IR (-O0):
@.str = [11 x i8] c"/etc/group\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"Err(%d) %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@EOF = global i64 0
@.str.3 = [21 x i8] c"Err(%d) %s: fputs()\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [516 x i8]
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %8
%9 = load i8*, i8** %8
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %21
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = load i8*, i8** %8
%18 = call i32 (i32, i8*, i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %14, i8* %16, i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
br label %22
22: ; preds = %41, %21
%23 = getelementptr inbounds [516 x i8], [516 x i8]* %7, i64 0, i64 0
%24 = load i32*, i32** %6
%25 = call i32* @fgets(i8* %23, i32 516, i32* %24)
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %42
27: ; preds = %22
%28 = getelementptr inbounds [516 x i8], [516 x i8]* %7, i64 0, i64 0
%29 = load i32, i32* @stdout
%30 = call i64 @fputs(i8* %28, i32 %29)
%31 = load i64, i64* @EOF
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %41
33: ; preds = %27
%34 = load i32, i32* @stderr
%35 = load i32, i32* @errno
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i32, i8*, i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %35, i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %27
br label %22
42: ; preds = %22
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
%45 = load i32, i32* @EXIT_SUCCESS
ret i32 %45
}

LLVM IR (-O2):
@.str = [11 x i8] c"/etc/group\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [16 x i8] c"Err(%d) %s: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@EOF = global i64 0
@.str.3 = [21 x i8] c"Err(%d) %s: fputs()\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [516 x i8]
%4 = getelementptr inbounds [516 x i8], [516 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %14
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 (i32, i8*, i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %9, i8* %10, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %2, %17
%15 = call i32* @fgets(i8* %4, i32 516, i32* %5)
%16 = icmp eq i32* %15, null
br i1 %16, label %29, label %17
17: ; preds = %14
%18 = load i32, i32* @stdout
%19 = call i64 @fputs(i8* %4, i32 %18)
%20 = load i64, i64* @EOF
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %14
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i32, i8*, i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %14
%30 = call i32 @fclose(i32* %5)
%31 = load i32, i32* @EXIT_SUCCESS
ret i32 %31
}