#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*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, int *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  FILE *fp;
  int a, b = -1;
  if (argc != 2) {
    printf("Usage: %s [FILE]\n", argv[0]);
    return 1;
  }
  fp = fopen(*++argv, "r");
  while (fscanf(fp, "%d", &a) != EOF) {
    if (a != b) {
      if (b >= 0)
        printf(",");
      printf("%d", a);
      b = a;
    }
    if (getc(fp) != ',') {
      printf("\n");
      b = -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x20(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1188 <main+0x48>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1240 <main+0x100>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rdi
lea    0xe70(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe5e(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <fscanf@plt>
mov    0x2e22(%rip),%rcx
cmp    (%rcx),%rax
je     1239 <main+0xf9>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     120a <main+0xca>
cmpl   $0x0,-0x20(%rbp)
jl     11f3 <main+0xb3>
lea    0xe2b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe17(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <getc@plt>
movsbl %al,%eax
cmp    $0x2c,%eax
je     1234 <main+0xf4>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x20(%rbp)
jmp    11ab <main+0x6b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    1219 <main+0xc9>
mov    0x8(%rsi),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe95(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
mov    %rax,%rcx
mov    0x2e52(%rip),%r12
xor    %eax,%eax
cmp    (%r12),%rcx
je     1233 <main+0xe3>
mov    $0xffffffff,%ebp
lea    0xe66(%rip),%r14
lea    0xc(%rsp),%r15
jmp    11d4 <main+0x84>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <fscanf@plt>
cmp    (%r12),%rax
je     1231 <main+0xe1>
mov    0xc(%rsp),%esi
cmp    %ebp,%esi
je     11fc <main+0xac>
test   %ebp,%ebp
js     11ee <main+0x9e>
mov    $0x2c,%edi
call   1030 <putchar@plt>
mov    0xc(%rsp),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0xc(%rsp),%ebp
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    $0x2c,%al
je     11c0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0xffffffff,%ebp
jmp    11c0 <main+0x70>
mov    (%rsi),%rsi
lea    0xddd(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
jmp    1233 <main+0xe3>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.3 = [2 x i8] c",\00"
@.str.4 = [2 x i8] c"\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %48
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i32 1
store i8** %18, i8*** %5
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
br label %21
21: ; preds = %46, %16
%22 = load i32*, i32** %6
%23 = call i64 @fscanf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %7)
%24 = load i64, i64* @EOF
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %47
26: ; preds = %21
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %39
30: ; preds = %26
%31 = load i32, i32* %8
%32 = icmp sge i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
%36 = load i32, i32* %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = load i32, i32* %7
store i32 %38, i32* %8
br label %39
39: ; preds = %35, %26
%40 = load i32*, i32** %6
%41 = call signext i8 @getc(i32* %40)
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 44
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %8
br label %46
46: ; preds = %44, %39
br label %21
47: ; preds = %21
store i32 0, i32* %3
br label %48
48: ; preds = %47, %11
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [18 x i8] c"Usage: %s [FILE]\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%d\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %40
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %40, label %16
16: ; preds = %9, %35
%17 = phi i32 [ %36, %35 ], [ -1, %9 ]
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, %17
br i1 %19, label %29, label %20
20: ; preds = %16
%21 = icmp sgt i32 %17, -1
br i1 %21, label %22, label %25
22: ; preds = %20
%23 = call i32 @putchar(i32 44)
%24 = load i32, i32* %3
br label %25
25: ; preds = %22, %20
%26 = phi i32 [ %24, %22 ], [ %18, %20 ]
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %3
br label %29
29: ; preds = %25, %16
%30 = phi i32 [ %28, %25 ], [ %17, %16 ]
%31 = call signext i8 @getc(i32* %12)
%32 = icmp eq i8 %31, 44
br i1 %32, label %35, label %33
33: ; preds = %29
%34 = call i32 @putchar(i32 10)
br label %35
35: ; preds = %33, %29
%36 = phi i32 [ -1, %33 ], [ %30, %29 ]
%37 = call i64 @fscanf(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%38 = load i64, i64* @EOF
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %16
40: ; preds = %35, %9, %6
%41 = phi i32 [ 1, %6 ], [ 0, %9 ], [ 0, %35 ]
ret i32 %41
}