#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 */

/* Variables and functions */
int character_count(char, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ piece(char *, char, char *, int);
int /*<<< orphan*/ piece_replace(char *, char, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int main(void) {
  char input_buffer[1024];
  char piece_buffer[128];
  int i;
  int comma_count;
  while (get_line(input_buffer, stdin)) {
    comma_count = character_count(',', input_buffer);
    for (i = 0; i <= comma_count; i++) {
      *piece_buffer = '\0';
      piece(piece_buffer, ',', input_buffer, i);
      if (!*piece_buffer) {
        piece_replace(input_buffer, ',', "0", i);
      }
    }
    printf("%s\n", input_buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     1235 <main+0xe5>
lea    -0x410(%rbp),%rsi
mov    $0x2c,%edi
call   1050 <character_count@plt>
mov    %eax,-0x498(%rbp)
movl   $0x0,-0x494(%rbp)
mov    -0x494(%rbp),%eax
cmp    -0x498(%rbp),%eax
jg     121d <main+0xcd>
movb   $0x0,-0x490(%rbp)
lea    -0x490(%rbp),%rdi
lea    -0x410(%rbp),%rdx
mov    -0x494(%rbp),%ecx
mov    $0x2c,%esi
call   1070 <piece@plt>
cmpb   $0x0,-0x490(%rbp)
jne    1204 <main+0xb4>
lea    -0x410(%rbp),%rdi
mov    -0x494(%rbp),%ecx
mov    $0x2c,%esi
lea    0xe01(%rip),%rdx
call   1060 <piece_replace@plt>
jmp    1209 <main+0xb9>
mov    -0x494(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x494(%rbp)
jmp    11a2 <main+0x52>
lea    -0x410(%rbp),%rsi
lea    0xdd7(%rip),%rdi
call   1040 <printf@plt>
jmp    1162 <main+0x12>
xor    %eax,%eax
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x488,%rsp
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0x80(%rsp),%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     1217 <main+0xc7>
lea    0x80(%rsp),%r13
lea    0xe73(%rip),%r14
mov    %rsp,%r15
lea    0xe67(%rip),%r12
jmp    11c1 <main+0x71>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <printf@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     1217 <main+0xc7>
mov    $0x2c,%edi
mov    %r13,%rsi
call   1050 <character_count@plt>
test   %eax,%eax
js     11a0 <main+0x50>
mov    %eax,%ebp
add    $0x1,%ebp
xor    %ebx,%ebx
jmp    11e7 <main+0x97>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
cmp    %ebx,%ebp
je     11a0 <main+0x50>
movb   $0x0,(%rsp)
mov    %r15,%rdi
mov    $0x2c,%esi
mov    %r13,%rdx
mov    %ebx,%ecx
call   1070 <piece@plt>
cmpb   $0x0,(%rsp)
jne    11e0 <main+0x90>
mov    %r13,%rdi
mov    $0x2c,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1060 <piece_replace@plt>
jmp    11e0 <main+0x90>
xor    %eax,%eax
add    $0x488,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [2 x i8] c"0\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
br label %6
6: ; preds = %35, %0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i64 @get_line(i8* %7, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %38
11: ; preds = %6
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = call i32 @character_count(i8 signext 44, i8* %12)
store i32 %13, i32* %5
store i32 0, i32* %4
br label %14
14: ; preds = %32, %11
%15 = load i32, i32* %4
%16 = load i32, i32* %5
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %35
18: ; preds = %14
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
store i8 0, i8* %19
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%22 = load i32, i32* %4
%23 = call i32 @piece(i8* %20, i8 signext 44, i8* %21, i32 %22)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%25 = load i8, i8* %24
%26 = icmp ne i8 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %18
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%29 = load i32, i32* %4
%30 = call i32 @piece_replace(i8* %28, i8 signext 44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %27, %18
br label %32
32: ; preds = %31
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %14
35: ; preds = %14
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %6
38: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [2 x i8] c"0\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i64 @get_line(i8* %3, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %26, label %8
8: ; preds = %0, %21
%9 = call i32 @character_count(i8 signext 44, i8* %3)
%10 = icmp slt i32 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %8, %18
%12 = phi i32 [ %19, %18 ], [ 0, %8 ]
store i8 0, i8* %4
%13 = call i32 @piece(i8* %4, i8 signext 44, i8* %3, i32 %12)
%14 = load i8, i8* %4
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @piece_replace(i8* %3, i8 signext 44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %18
18: ; preds = %11, %16
%19 = add nuw i32 %12, 1
%20 = icmp eq i32 %12, %9
br i1 %20, label %21, label %11
21: ; preds = %18, %8
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%23 = load i32, i32* @stdin
%24 = call i64 @get_line(i8* %3, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %8
26: ; preds = %21, %0
ret i32 0
}