#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 /*<<< orphan*/ erase_outgoing_msgid(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ isgrouponserver(char *);
scalar_t__ ismsgidonserver(char *);
int /*<<< orphan*/ myerror(char *, char *);
int /*<<< orphan*/ notice(char *, char *);
int post_MAIL(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int mail2news(int argc, char *fname, char *newsgroups, char *subject) {
  char buf[512];
  char msgid[128];
  char *s;
  FILE *in;
  int rc;
  if (fname == NULL) {
    in = stdin;
  } else {
    if ((in = fopen(fname, "r")) == NULL) {
      myerror("cant open input file %s", fname);
      fprintf(stderr, "cant open input file %s\n", fname);
      return 1;
    }
  }
  if (!isgrouponserver(newsgroups)) {
    notice("Group not found: %s", newsgroups);
    fprintf(stderr, "Group not found: %s\n", newsgroups);
  }
  while (fgets(buf, 512 - 1, in)) {
    if ((s = strchr(buf, '\n')) != NULL)
      *s = '\0';
    if (strncmp(buf, "Message-ID: ", 12) == 0) {
      strncpy(msgid, &buf[12], 128);
      if (ismsgidonserver(msgid)) {
        myerror("Message-ID of %s already in use upstream", msgid);
        fprintf(stderr, "Message-ID of %s already in use upstream\n", msgid);
        fclose(in);
        return 1;
      }
      break;
    }
  }
  rc = post_MAIL(in, newsgroups, subject);
  fclose(in);
  if (rc == 0)
    fprintf(stderr, "Failed posting\n");
  erase_outgoing_msgid(msgid);
  return !rc;
}


x86 assembly (clang, -O0):
<mail2news>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120b <mail2news+0x3b>
mov    0x2dec(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x2b0(%rbp)
jmp    1268 <mail2news+0x98>
mov    -0x10(%rbp),%rdi
lea    0xdea(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x2b0(%rbp)
cmp    $0x0,%rax
jne    1263 <mail2news+0x93>
mov    -0x10(%rbp),%rsi
lea    0xdcb(%rip),%rdi
call   1090 <myerror@plt>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1409 <mail2news+0x239>
jmp    1268 <mail2news+0x98>
mov    -0x18(%rbp),%rdi
call   10b0 <isgrouponserver@plt>
cmp    $0x0,%eax
jne    12a5 <mail2news+0xd5>
mov    -0x18(%rbp),%rsi
lea    0xdae(%rip),%rdi
call   10f0 <notice@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
jmp    12aa <mail2news+0xda>
lea    -0x220(%rbp),%rdi
mov    -0x2b0(%rbp),%rdx
mov    $0x1ff,%esi
call   10c0 <fgets@plt>
cmp    $0x0,%rax
je     139f <mail2news+0x1cf>
lea    -0x220(%rbp),%rdi
mov    $0xa,%esi
call   10a0 <strchr@plt>
mov    %rax,-0x2a8(%rbp)
cmp    $0x0,%rax
je     12f8 <mail2news+0x128>
mov    -0x2a8(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x220(%rbp),%rdi
lea    0xd56(%rip),%rsi
mov    $0xc,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    139a <mail2news+0x1ca>
lea    -0x2a0(%rbp),%rdi
lea    -0x220(%rbp),%rsi
add    $0xc,%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
lea    -0x2a0(%rbp),%rdi
call   1070 <ismsgidonserver@plt>
cmp    $0x0,%rax
je     1395 <mail2news+0x1c5>
lea    -0x2a0(%rbp),%rsi
lea    0xd0f(%rip),%rdi
call   1090 <myerror@plt>
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
lea    -0x2a0(%rbp),%rdx
lea    0xd1c(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x2b0(%rbp),%rdi
call   1080 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1409 <mail2news+0x239>
jmp    139f <mail2news+0x1cf>
jmp    12aa <mail2news+0xda>
mov    -0x2b0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <post_MAIL@plt>
mov    %eax,-0x2b4(%rbp)
mov    -0x2b0(%rbp),%rdi
call   1080 <fclose@plt>
cmpl   $0x0,-0x2b4(%rbp)
jne    13e9 <mail2news+0x219>
mov    0x2bff(%rip),%rax
mov    (%rax),%edi
lea    0xcda(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
lea    -0x2a0(%rbp),%rdi
call   1050 <erase_outgoing_msgid@plt>
cmpl   $0x0,-0x2b4(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mail2news>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x288,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
test   %rsi,%rsi
je     1239 <mail2news+0x69>
mov    %rsi,%rbx
lea    0xe0a(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1243 <mail2news+0x73>
lea    0xdf5(%rip),%rdi
mov    %rbx,%rsi
call   1090 <myerror@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xdf5(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%ebp
jmp    1374 <mail2news+0x1a4>
mov    0x2da8(%rip),%rax
mov    (%rax),%r12
mov    %r15,%rdi
call   10b0 <isgrouponserver@plt>
test   %eax,%eax
jne    1278 <mail2news+0xa8>
lea    0xddd(%rip),%rdi
mov    %r15,%rsi
call   10f0 <notice@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
lea    0x80(%rsp),%rbx
lea    0xdd5(%rip),%r13
jmp    12a5 <mail2news+0xd5>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0xc,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     12d1 <mail2news+0x101>
mov    %rbx,%rdi
mov    $0x1ff,%esi
mov    %r12,%rdx
call   10c0 <fgets@plt>
test   %rax,%rax
je     1331 <mail2news+0x161>
mov    %rbx,%rdi
mov    $0xa,%esi
call   10a0 <strchr@plt>
test   %rax,%rax
je     1290 <mail2news+0xc0>
movb   $0x0,(%rax)
jmp    1290 <mail2news+0xc0>
lea    0x8c(%rsp),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1070 <ismsgidonserver@plt>
test   %rax,%rax
je     1331 <mail2news+0x161>
lea    0xd6c(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1090 <myerror@plt>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %r12,%rdi
call   1080 <fclose@plt>
mov    $0x1,%ebp
jmp    1374 <mail2news+0x1a4>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <post_MAIL@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1080 <fclose@plt>
test   %ebx,%ebx
jne    1364 <mail2news+0x194>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
xor    %ebp,%ebp
test   %ebx,%ebx
sete   %bpl
mov    %rsp,%rdi
call   1050 <erase_outgoing_msgid@plt>
mov    %ebp,%eax
add    $0x288,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"cant open input file %s\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"cant open input file %s\0A\00"
@.str.3 = [20 x i8] c"Group not found: %s\00"
@.str.4 = [21 x i8] c"Group not found: %s\0A\00"
@.str.5 = [13 x i8] c"Message-ID: \00"
@.str.6 = [41 x i8] c"Message-ID of %s already in use upstream\00"
@.str.7 = [42 x i8] c"Message-ID of %s already in use upstream\0A\00"
@.str.8 = [16 x i8] c"Failed posting\0A\00"
define i32 @mail2news(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [512 x i8]
%11 = alloca [128 x i8]
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32*, i32** @stdin
store i32* %18, i32** %13
br label %30
19: ; preds = %4
%20 = load i8*, i8** %7
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %13
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i8*, i8** %7
%25 = call i32 @myerror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %7
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %27)
store i32 1, i32* %5
br label %92
29: ; preds = %19
br label %30
30: ; preds = %29, %17
%31 = load i8*, i8** %8
%32 = call i32 @isgrouponserver(i8* %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %40, label %34
34: ; preds = %30
%35 = load i8*, i8** %8
%36 = call i32 @notice(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %8
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %34, %30
br label %41
41: ; preds = %72, %40
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%43 = load i32*, i32** %13
%44 = call i64 @fgets(i8* %42, i32 511, i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %73
46: ; preds = %41
%47 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%48 = call i8* @strchr(i8* %47, i8 signext 10)
store i8* %48, i8** %12
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %52
50: ; preds = %46
%51 = load i8*, i8** %12
store i8 0, i8* %51
br label %52
52: ; preds = %50, %46
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%54 = call i64 @strncmp(i8* %53, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 12)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %72
56: ; preds = %52
%57 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%58 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 12
%59 = call i32 @strncpy(i8* %57, i8* %58, i32 128)
%60 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%61 = call i64 @ismsgidonserver(i8* %60)
%62 = icmp ne i64 %61, 0
br i1 %62, label %63, label %71
63: ; preds = %56
%64 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%65 = call i32 @myerror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i8* %64)
%66 = load i32, i32* @stderr
%67 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %67)
%69 = load i32*, i32** %13
%70 = call i32 @fclose(i32* %69)
store i32 1, i32* %5
br label %92
71: ; preds = %56
br label %73
72: ; preds = %52
br label %41
73: ; preds = %71, %41
%74 = load i32*, i32** %13
%75 = load i8*, i8** %8
%76 = load i8*, i8** %9
%77 = call i32 @post_MAIL(i32* %74, i8* %75, i8* %76)
store i32 %77, i32* %14
%78 = load i32*, i32** %13
%79 = call i32 @fclose(i32* %78)
%80 = load i32, i32* %14
%81 = icmp eq i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %73
%83 = load i32, i32* @stderr
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %85
85: ; preds = %82, %73
%86 = getelementptr inbounds [128 x i8], [128 x i8]* %11, i64 0, i64 0
%87 = call i32 @erase_outgoing_msgid(i8* %86)
%88 = load i32, i32* %14
%89 = icmp ne i32 %88, 0
%90 = xor i1 %89, true
%91 = zext i1 %90 to i32
store i32 %91, i32* %5
br label %92
92: ; preds = %85, %63, %23
%93 = load i32, i32* %5
ret i32 %93
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"cant open input file %s\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"cant open input file %s\0A\00"
@.str.3 = [20 x i8] c"Group not found: %s\00"
@.str.4 = [21 x i8] c"Group not found: %s\0A\00"
@.str.5 = [13 x i8] c"Message-ID: \00"
@.str.6 = [41 x i8] c"Message-ID of %s already in use upstream\00"
@.str.7 = [42 x i8] c"Message-ID of %s already in use upstream\0A\00"
@.str.8 = [16 x i8] c"Failed posting\0A\00"
define i32 @mail2news(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [512 x i8]
%6 = alloca [128 x i8]
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%9 = icmp eq i8* %1, null
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = load i32*, i32** @stdin
br label %19
12: ; preds = %4
%13 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = tail call i32 @myerror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %1)
br label %58
19: ; preds = %12, %10
%20 = phi i32* [ %11, %10 ], [ %13, %12 ]
%21 = tail call i32 @isgrouponserver(i8* %2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = tail call i32 @notice(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %27
27: ; preds = %23, %19
br label %28
28: ; preds = %27, %35
%29 = call i64 @fgets(i8* %7, i32 511, i32* %20)
%30 = icmp eq i64 %29, 0
br i1 %30, label %48, label %31
31: ; preds = %28
%32 = call i8* @strchr(i8* %7, i8 signext 10)
%33 = icmp eq i8* %32, null
br i1 %33, label %35, label %34
34: ; preds = %31
store i8 0, i8* %32
br label %35
35: ; preds = %34, %31
%36 = call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i32 12)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %28
38: ; preds = %35
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 12
%40 = call i32 @strncpy(i8* %8, i8* %39, i32 128)
%41 = call i64 @ismsgidonserver(i8* %8)
%42 = icmp eq i64 %41, 0
br i1 %42, label %48, label %43
43: ; preds = %38
%44 = call i32 @myerror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i8* %8)
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %8)
%47 = call i32 @fclose(i32* %20)
br label %58
48: ; preds = %28, %38
%49 = call i32 @post_MAIL(i32* %20, i8* %2, i8* %3)
%50 = call i32 @fclose(i32* %20)
%51 = icmp eq i32 %49, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %55
55: ; preds = %52, %48
%56 = call i32 @erase_outgoing_msgid(i8* %8)
%57 = zext i1 %51 to i32
br label %58
58: ; preds = %55, %43, %15
%59 = phi i32 [ 1, %43 ], [ %57, %55 ], [ 1, %15 ]
ret i32 %59
}