#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*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ *freopen(char *, char *, int /*<<< orphan*/);
int scanf(char *, int *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strtol(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ write(int, int *, int);
int main(int argc, char **argv) {
  if (argc != 3) {
    fprintf(stderr, "red: wrong number of parameters\n");
    exit(-1);
  }
  int node, len, id, msg;
  int red, st, num, i, j;
  char *filename;
  FILE *f;
  red = strtol(argv[1], NULL, 10);
  filename = argv[2];
  f = freopen(filename, "r", stdin);
  if (f == NULL) {
    fprintf(stderr, "file %s permission denied\n", filename);
    exit(-1);
  }
  st = scanf("%d", &num);
  for (i = 0; i < num; i++) {
    st = scanf("%d%d%d", &id, &msg, &len);
    assert(write(1, &id, sizeof(int)));
    assert(write(1, &msg, sizeof(int)));
    assert(write(1, &len, sizeof(int)));
    for (j = 0; j < len; j++) {
      st = scanf("%d", &node);
      assert(write(1, &node, sizeof(int)));
    }
  }
  fprintf(stderr, "Red [%d]: %d packets transmitted\n", red, i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b1 <main+0x41>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
lea    0xe37(%rip),%rsi
call   1040 <freopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1223 <main+0xb3>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
mov    -0x40(%rbp),%rdx
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    0xe18(%rip),%rdi
lea    -0x2c(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1319 <main+0x1a9>
lea    0xdec(%rip),%rdi
lea    -0x1c(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x18(%rbp),%rcx
mov    $0x0,%al
call   1080 <scanf@plt>
mov    %eax,-0x28(%rbp)
mov    $0x1,%edi
lea    -0x1c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    $0x1,%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    $0x1,%edi
lea    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%edi
call   1050 <assert@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1306 <main+0x196>
lea    0xd72(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
mov    %eax,-0x28(%rbp)
mov    $0x1,%edi
lea    -0x14(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    12bd <main+0x14d>
jmp    130b <main+0x19b>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    123f <main+0xcf>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
mov    -0x30(%rbp),%ecx
lea    0xd16(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x3,%edi
jne    12f4 <main+0x184>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,0x8(%rsp)
mov    0x10(%rbp),%rbp
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
lea    0xe6d(%rip),%rsi
mov    %rbp,%rdi
call   1040 <freopen@plt>
test   %rax,%rax
je     1315 <main+0x1a5>
lea    0xe76(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
cmpl   $0x0,(%rsp)
jle    12c6 <main+0x156>
lea    0x4(%rsp),%r13
lea    0xe56(%rip),%r14
lea    0x14(%rsp),%r15
xor    %ebx,%ebx
jmp    120c <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebx
cmp    (%rsp),%ebx
jge    12c6 <main+0x156>
lea    0xe2b(%rip),%rdi
lea    0x10(%rsp),%rbp
mov    %rbp,%rsi
lea    0xc(%rsp),%r12
mov    %r12,%rdx
mov    %r13,%rcx
xor    %eax,%eax
call   1080 <scanf@plt>
mov    $0x1,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    $0x1,%edi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%edi
call   1050 <assert@plt>
mov    $0x1,%edi
mov    %r13,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%edi
call   1050 <assert@plt>
cmpl   $0x0,0x4(%rsp)
jle    1200 <main+0x90>
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
mov    $0x1,%edi
mov    %r15,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %eax,%edi
call   1050 <assert@plt>
add    $0x1,%r12d
cmp    0x4(%rsp),%r12d
jl     1290 <main+0x120>
jmp    1200 <main+0x90>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
mov    0x8(%rsp),%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cdd(%rip),%rax
mov    (%rax),%edi
lea    0xcfc(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
lea    0xcfe(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"red: wrong number of parameters\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [27 x i8] c"file %s permission denied\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [7 x i8] c"%d%d%d\00"
@.str.5 = [34 x i8] c"Red [%d]: %d packets transmitted\0A\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
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strtol(i8* %26, i32* null, i32 10)
store i32 %27, i32* %10
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
store i8* %30, i8** %15
%31 = load i8*, i8** %15
%32 = load i32, i32* @stdin
%33 = call i32* @freopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %32)
store i32* %33, i32** %16
%34 = load i32*, i32** %16
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %41
36: ; preds = %23
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %15
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %38)
%40 = call i32 @exit(i32 -1)
unreachable
41: ; preds = %23
%42 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %12)
store i32 %42, i32* %11
store i32 0, i32* %13
br label %43
43: ; preds = %67, %41
%44 = load i32, i32* %13
%45 = load i32, i32* %12
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %70
47: ; preds = %43
%48 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %8, i32* %9, i32* %7)
store i32 %48, i32* %11
%49 = call i32 @write(i32 1, i32* %8, i32 4)
%50 = call i32 @assert(i32 %49)
%51 = call i32 @write(i32 1, i32* %9, i32 4)
%52 = call i32 @assert(i32 %51)
%53 = call i32 @write(i32 1, i32* %7, i32 4)
%54 = call i32 @assert(i32 %53)
store i32 0, i32* %14
br label %55
55: ; preds = %63, %47
%56 = load i32, i32* %14
%57 = load i32, i32* %7
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %66
59: ; preds = %55
%60 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
store i32 %60, i32* %11
%61 = call i32 @write(i32 1, i32* %6, i32 4)
%62 = call i32 @assert(i32 %61)
br label %63
63: ; preds = %59
%64 = load i32, i32* %14
%65 = add nsw i32 %64, 1
store i32 %65, i32* %14
br label %55
66: ; preds = %55
br label %67
67: ; preds = %66
%68 = load i32, i32* %13
%69 = add nsw i32 %68, 1
store i32 %69, i32* %13
br label %43
70: ; preds = %43
%71 = load i32, i32* @stderr
%72 = load i32, i32* %10
%73 = load i32, i32* %13
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %72, i32 %73)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"red: wrong number of parameters\0A\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [27 x i8] c"file %s permission denied\0A\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [7 x i8] c"%d%d%d\00"
@.str.5 = [34 x i8] c"Red [%d]: %d packets transmitted\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = icmp eq i32 %0, 3
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 -1)
unreachable
13: ; preds = %2
%14 = bitcast i32* %3 to i8*
%15 = bitcast i32* %4 to i8*
%16 = bitcast i32* %5 to i8*
%17 = bitcast i32* %6 to i8*
%18 = bitcast i32* %7 to i8*
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32 @strtol(i8* nocapture %20, i32* null, i32 10)
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = load i32, i32* @stdin
%25 = tail call i32* @freopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %13
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%30 = tail call i32 @exit(i32 -1)
unreachable
31: ; preds = %13
%32 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %7)
%33 = load i32, i32* %7
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %58
35: ; preds = %31, %54
%36 = phi i32 [ %55, %54 ], [ 0, %31 ]
%37 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %5, i32* %6, i32* %4)
%38 = call i32 @write(i32 1, i32* %5, i32 4)
%39 = call i32 @assert(i32 %38)
%40 = call i32 @write(i32 1, i32* %6, i32 4)
%41 = call i32 @assert(i32 %40)
%42 = call i32 @write(i32 1, i32* %4, i32 4)
%43 = call i32 @assert(i32 %42)
%44 = load i32, i32* %4
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %35, %46
%47 = phi i32 [ %51, %46 ], [ 0, %35 ]
%48 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%49 = call i32 @write(i32 1, i32* %3, i32 4)
%50 = call i32 @assert(i32 %49)
%51 = add nuw nsw i32 %47, 1
%52 = load i32, i32* %4
%53 = icmp slt i32 %51, %52
br i1 %53, label %46, label %54
54: ; preds = %46, %35
%55 = add nuw nsw i32 %36, 1
%56 = load i32, i32* %7
%57 = icmp slt i32 %55, %56
br i1 %57, label %35, label %58
58: ; preds = %54, %31
%59 = phi i32 [ 0, %31 ], [ %55, %54 ]
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0), i32 %21, i32 %59)
ret i32 0
}