#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 */
double atof(char *);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, 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*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char input_buffer[1024];
  char piece_buffer[1024];
  char delimiter;
  int piece_integer;
  double float_value;
  int integer_value;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s piece_integer delimiter\n", argv[0]);
    exit(1);
  }
  piece_integer = atoi(argv[1]);
  delimiter = *argv[2];
  while (get_line(input_buffer, stdin)) {
    if (!piece(piece_buffer, delimiter, input_buffer, piece_integer)) {
      fprintf(stderr, "%s warning: cannot piece (%s)\n", argv[0], input_buffer);
      continue;
    }
    float_value = atof(piece_buffer);
    if (float_value == 0.0)
      integer_value = 0;
    else if (float_value > 0.0)
      integer_value = (int)(float_value + 0.5);
    else
      integer_value = (int)(float_value - 0.5);
    sprintf(piece_buffer, "%d", integer_value);
    piece_replace(input_buffer, delimiter, piece_buffer, piece_integer);
    printf("%s\n", input_buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11db <main+0x4b>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x818(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%al
mov    %al,-0x811(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
call   1040 <get_line@plt>
cmp    $0x0,%rax
je     135a <main+0x1ca>
lea    -0x810(%rbp),%rdi
mov    -0x811(%rbp),%al
lea    -0x410(%rbp),%rdx
mov    -0x818(%rbp),%ecx
movsbl %al,%esi
call   10b0 <piece@plt>
cmp    $0x0,%eax
jne    1272 <main+0xe2>
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    -0x410(%rbp),%rcx
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    11fe <main+0x6e>
lea    -0x810(%rbp),%rdi
call   1030 <atof@plt>
movsd  %xmm0,-0x820(%rbp)
ff
movsd  -0x820(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    12b0 <main+0x120>
jp     12b0 <main+0x120>
movl   $0x0,-0x824(%rbp)
jmp    1307 <main+0x177>
movsd  -0x820(%rbp),%xmm0
ff
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12e4 <main+0x154>
movsd  0xd33(%rip),%xmm0
addsd  -0x820(%rbp),%xmm0
ff
cvttsd2si %xmm0,%eax
mov    %eax,-0x824(%rbp)
jmp    1302 <main+0x172>
movsd  -0x820(%rbp),%xmm0
ff
movsd  0xd0c(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x824(%rbp)
jmp    1307 <main+0x177>
lea    -0x810(%rbp),%rdi
mov    -0x824(%rbp),%edx
lea    0xd2f(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x811(%rbp),%al
lea    -0x810(%rbp),%rdx
mov    -0x818(%rbp),%ecx
movsbl %al,%esi
call   1070 <piece_replace@plt>
lea    -0x410(%rbp),%rsi
lea    0xcfd(%rip),%rdi
call   1050 <printf@plt>
jmp    11fe <main+0x6e>
xor    %eax,%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jne    12a3 <main+0x113>
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%r14),%rax
mov    (%rax),%bl
mov    0x2e22(%rip),%r13
mov    0x0(%r13),%esi
mov    %rsp,%rdi
call   1040 <get_line@plt>
test   %rax,%rax
je     128f <main+0xff>
movsbl %bl,%ebx
lea    0x400(%rsp),%r12
mov    %rsp,%rbp
jmp    1236 <main+0xa6>
addsd  0xe0d(%rip),%xmm0
cvttsd2si %xmm0,%edx
mov    %r12,%rdi
lea    0xe59(%rip),%rsi
call   1090 <sprintf@plt>
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r12,%rdx
mov    %r15d,%ecx
call   1070 <piece_replace@plt>
lea    0xe40(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
mov    0x0(%r13),%esi
mov    %rbp,%rdi
call   1040 <get_line@plt>
test   %rax,%rax
je     128f <main+0xff>
mov    %r12,%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
mov    %r15d,%ecx
call   10b0 <piece@plt>
test   %eax,%eax
je     1270 <main+0xe0>
mov    %r12,%rdi
call   1030 <atof@plt>
xor    %edx,%edx
ucomisd 0xdb4(%rip),%xmm0
jne    1260 <main+0xd0>
jnp    11f7 <main+0x67>
jbe    11eb <main+0x5b>
addsd  0xd9e(%rip),%xmm0
jmp    11f3 <main+0x63>
nopl   0x0(%rax)
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdb8(%rip),%rsi
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1225 <main+0x95>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd62(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Usage: %s piece_integer delimiter\0A\00"
@stdin = global i32 0
@.str.1 = [31 x i8] c"%s warning: cannot piece (%s)\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i8
%9 = alloca i32
%10 = alloca double
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %9
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = load i8, i8* %28
store i8 %29, i8* %8
br label %30
30: ; preds = %67, %42, %21
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%32 = load i32, i32* @stdin
%33 = call i64 @get_line(i8* %31, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %78
35: ; preds = %30
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = load i8, i8* %8
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%39 = load i32, i32* %9
%40 = call i32 @piece(i8* %36, i8 signext %37, i8* %38, i32 %39)
%41 = icmp ne i32 %40, 0
br i1 %41, label %49, label %42
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* %47)
br label %30
49: ; preds = %35
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%51 = call double @atof(i8* %50)
store double %51, double* %10
%52 = load double, double* %10
%53 = fcmp oeq double %52, 0.000000e+00
br i1 %53, label %54, label %55
54: ; preds = %49
store i32 0, i32* %11
br label %67
55: ; preds = %49
%56 = load double, double* %10
%57 = fcmp ogt double %56, 0.000000e+00
br i1 %57, label %58, label %62
58: ; preds = %55
%59 = load double, double* %10
%60 = fadd double %59, 5.000000e-01
%61 = fptosi double %60 to i32
store i32 %61, i32* %11
br label %66
62: ; preds = %55
%63 = load double, double* %10
%64 = fsub double %63, 5.000000e-01
%65 = fptosi double %64 to i32
store i32 %65, i32* %11
br label %66
66: ; preds = %62, %58
br label %67
67: ; preds = %66, %54
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%69 = load i32, i32* %11
%70 = call i32 @sprintf(i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %69)
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%72 = load i8, i8* %8
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%74 = load i32, i32* %9
%75 = call i32 @piece_replace(i8* %71, i8 signext %72, i8* %73, i32 %74)
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%77 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %76)
br label %30
78: ; preds = %30
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Usage: %s piece_integer delimiter\0A\00"
@stdin = global i32 0
@.str.1 = [31 x i8] c"%s warning: cannot piece (%s)\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 3
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = load i8, i8* %18
%20 = load i32, i32* @stdin
%21 = call i64 @get_line(i8* %5, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %50, label %23
23: ; preds = %13, %30
%24 = call i32 @piece(i8* %6, i8 signext %19, i8* %5, i32 %16)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %5)
br label %30
30: ; preds = %26, %45
%31 = load i32, i32* @stdin
%32 = call i64 @get_line(i8* %5, i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %50, label %23
34: ; preds = %23
%35 = call double @atof(i8* %6)
%36 = fcmp oeq double %35, 0.000000e+00
br i1 %36, label %45, label %37
37: ; preds = %34
%38 = fcmp ogt double %35, 0.000000e+00
br i1 %38, label %39, label %42
39: ; preds = %37
%40 = fadd double %35, 5.000000e-01
%41 = fptosi double %40 to i32
br label %45
42: ; preds = %37
%43 = fadd double %35, -5.000000e-01
%44 = fptosi double %43 to i32
br label %45
45: ; preds = %34, %39, %42
%46 = phi i32 [ %41, %39 ], [ %44, %42 ], [ 0, %34 ]
%47 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %46)
%48 = call i32 @piece_replace(i8* %5, i8 signext %19, i8* %6, i32 %16)
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
br label %30
50: ; preds = %30, %13
ret i32 0
}