#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ setregid(int, int);
int snprintf(char *, int, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fp;
  char buf[256];
  char *filename;
  int lines, chars, cpl;
  setregid(1011, 1011);
  if (argc != 2) {
    fprintf(stderr, "Usage: %s filename\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  filename = argv[1];
  printf("Counting %s ... \n", filename);
  if (snprintf(buf, 256, "/usr/bin/wc -l %s", filename) >= 256) {
    fprintf(stderr, "Filename %s is too long!\n", filename);
    exit(EXIT_FAILURE);
  }
  fp = popen(buf, "r");
  if (!fp) {
    fprintf(stderr, "Command execution failed! Sorry!\n");
    exit(EXIT_FAILURE);
  }
  if (1 != fscanf(fp, "%d", &lines)) {
    fprintf(stderr, "Cannot scan! Sorry!\n");
  }
  pclose(fp);
  snprintf(buf, 256, "/usr/bin/wc -c %s", filename);
  fp = popen(buf, "r");
  if (!fp) {
    fprintf(stderr, "Command execution failed! Bummer!\n");
    exit(EXIT_FAILURE);
  }
  if (1 != fscanf(fp, "%d", &chars)) {
    fprintf(stderr, "Cannot scan! Sorry!\n");
  }
  pclose(fp);
  cpl = chars / lines;
  printf("Chars per line is %d.\n", cpl);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x3f3,%esi
mov    %esi,%edi
call   1080 <setregid@plt>
cmpl   $0x2,-0x8(%rbp)
je     11db <main+0x5b>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x128(%rbp)
mov    -0x128(%rbp),%rsi
lea    0xe1c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rcx
mov    $0x100,%esi
lea    0xe0d(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x100,%eax
jl     1255 <main+0xd5>
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
mov    -0x128(%rbp),%rdx
lea    0xdf8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x120(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    129c <main+0x11c>
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xdcd(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xdcf(%rip),%rsi
lea    -0x12c(%rbp),%rdx
call   1060 <fscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     12d9 <main+0x159>
mov    0x2d17(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rcx
mov    $0x100,%esi
lea    0xd92(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x120(%rbp),%rdi
lea    0xd43(%rip),%rsi
call   1090 <popen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1348 <main+0x1c8>
mov    0x2cb6(%rip),%rax
mov    (%rax),%edi
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c97(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xd23(%rip),%rsi
lea    -0x130(%rbp),%rdx
call   1060 <fscanf@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     1385 <main+0x205>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0x130(%rbp),%eax
cltd
idivl  -0x12c(%rbp)
mov    %eax,-0x134(%rbp)
mov    -0x134(%rbp),%esi
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c14(%rip),%rax
mov    (%rax),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x3f3,%edi
mov    $0x3f3,%esi
call   1080 <setregid@plt>
cmp    $0x2,%ebp
jne    12d3 <main+0x153>
mov    0x8(%rbx),%r14
lea    0xe61(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe62(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x100,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
cmp    $0x100,%eax
jge    12e8 <main+0x168>
lea    0xe6a(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1090 <popen@plt>
test   %rax,%rax
je     1304 <main+0x184>
mov    %rax,%rbx
lea    0xe71(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
je     122e <main+0xae>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <pclose@plt>
lea    0xe51(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r14,%rcx
call   1050 <snprintf@plt>
lea    0xdf9(%rip),%rsi
mov    %rbx,%rdi
call   1090 <popen@plt>
test   %rax,%rax
je     1316 <main+0x196>
mov    %rax,%rbx
lea    0xe02(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
je     129d <main+0x11d>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
lea    0xde3(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    0x8(%rsp),%eax
cltd
idivl  0xc(%rsp)
lea    0xe0e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%eax
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd1a(%rip),%rsi
jmp    12fb <main+0x17b>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    132d <main+0x1ad>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
lea    0xd40(%rip),%rsi
jmp    1326 <main+0x1a6>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
lea    0xd7a(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"Counting %s ... \0A\00"
@.str.2 = [18 x i8] c"/usr/bin/wc -l %s\00"
@.str.3 = [26 x i8] c"Filename %s is too long!\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [34 x i8] c"Command execution failed! Sorry!\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [21 x i8] c"Cannot scan! Sorry!\0A\00"
@.str.8 = [18 x i8] c"/usr/bin/wc -c %s\00"
@.str.9 = [35 x i8] c"Command execution failed! Bummer!\0A\00"
@.str.10 = [23 x i8] c"Chars per line is %d.\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 [256 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i32 @setregid(i32 1011, i32 1011)
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %23
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%30 = load i8*, i8** %8
%31 = call i32 @snprintf(i8* %29, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = icmp sge i32 %31, 256
br i1 %32, label %33, label %39
33: ; preds = %23
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %8
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %23
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%41 = call i32* @popen(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %41, i32** %6
%42 = load i32*, i32** %6
%43 = icmp ne i32* %42, null
br i1 %43, label %49, label %44
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %39
%50 = load i32*, i32** %6
%51 = call i32 @fscanf(i32* %50, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %9)
%52 = icmp ne i32 1, %51
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %56
56: ; preds = %53, %49
%57 = load i32*, i32** %6
%58 = call i32 @pclose(i32* %57)
%59 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%60 = load i8*, i8** %8
%61 = call i32 @snprintf(i8* %59, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* %60)
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%63 = call i32* @popen(i8* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %63, i32** %6
%64 = load i32*, i32** %6
%65 = icmp ne i32* %64, null
br i1 %65, label %71, label %66
66: ; preds = %56
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0))
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %56
%72 = load i32*, i32** %6
%73 = call i32 @fscanf(i32* %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %10)
%74 = icmp ne i32 1, %73
br i1 %74, label %75, label %78
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %78
78: ; preds = %75, %71
%79 = load i32*, i32** %6
%80 = call i32 @pclose(i32* %79)
%81 = load i32, i32* %10
%82 = load i32, i32* %9
%83 = sdiv i32 %81, %82
store i32 %83, i32* %11
%84 = load i32, i32* %11
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i32 %84)
%86 = load i32, i32* @EXIT_SUCCESS
ret i32 %86
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Usage: %s filename\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [18 x i8] c"Counting %s ... \0A\00"
@.str.2 = [18 x i8] c"/usr/bin/wc -l %s\00"
@.str.3 = [26 x i8] c"Filename %s is too long!\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [34 x i8] c"Command execution failed! Sorry!\0A\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [21 x i8] c"Cannot scan! Sorry!\0A\00"
@.str.8 = [18 x i8] c"/usr/bin/wc -c %s\00"
@.str.9 = [35 x i8] c"Command execution failed! Bummer!\0A\00"
@.str.10 = [23 x i8] c"Chars per line is %d.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 @setregid(i32 1011, i32 1011)
%10 = icmp eq i32 %0, 2
br i1 %10, label %17, label %11
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%22 = icmp sgt i32 %21, 255
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %19)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %17
%29 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %28
%37 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %4)
%38 = icmp eq i32 %37, 1
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %42
42: ; preds = %39, %36
%43 = call i32 @pclose(i32* %29)
%44 = call i32 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i8* %19)
%45 = call i32* @popen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %52
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.9, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %42
%53 = call i32 @fscanf(i32* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %5)
%54 = icmp eq i32 %53, 1
br i1 %54, label %58, label %55
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
br label %58
58: ; preds = %55, %52
%59 = call i32 @pclose(i32* %45)
%60 = load i32, i32* %5
%61 = load i32, i32* %4
%62 = sdiv i32 %60, %61
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.10, i64 0, i64 0), i32 %62)
%64 = load i32, i32* @EXIT_SUCCESS
ret i32 %64
}