#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 */
scalar_t__ check_editting_mode();
scalar_t__ ck_malloc(int);
int /*<<< orphan*/ put_string(char *, int);
void self_insert_command(int ch, int count) {
  if (check_editting_mode())
    return;
  else if (count == 1) {
    char chr = ch;
    put_string(&chr, 1);
  } else if (count > 0) {
    char *buf = (char *)ck_malloc(count);
    int x;
    for (x = 0; x < count; ++x)
      buf[x] = ch;
    put_string(buf, count);
  }
}


x86 assembly (clang, -O0):
<self_insert_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <check_editting_mode@plt>
cmp    $0x0,%rax
je     1154 <self_insert_command+0x24>
jmp    11d4 <self_insert_command+0xa4>
cmpl   $0x1,-0x8(%rbp)
jne    1177 <self_insert_command+0x47>
mov    -0x4(%rbp),%eax
mov    %al,-0x9(%rbp)
lea    -0x9(%rbp),%rdi
mov    $0x1,%esi
call   1050 <put_string@plt>
jmp    11cf <self_insert_command+0x9f>
cmpl   $0x0,-0x8(%rbp)
jle    11ca <self_insert_command+0x9a>
mov    -0x8(%rbp),%edi
call   1040 <ck_malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11be <self_insert_command+0x8e>
mov    -0x4(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1194 <self_insert_command+0x64>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <put_string@plt>
jmp    11cf <self_insert_command+0x9f>
jmp    11d4 <self_insert_command+0xa4>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<self_insert_command>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <check_editting_mode@plt>
test   %rax,%rax
jne    119d <self_insert_command+0x5d>
cmp    $0x1,%ebx
jne    1173 <self_insert_command+0x33>
mov    %bpl,0xf(%rsp)
lea    0xf(%rsp),%rdi
mov    $0x1,%esi
call   1060 <put_string@plt>
jmp    119d <self_insert_command+0x5d>
jl     119d <self_insert_command+0x5d>
mov    %ebx,%edi
call   1050 <ck_malloc@plt>
mov    %rax,%r14
mov    %ebx,%edx
mov    %rax,%rdi
mov    %ebp,%esi
call   1040 <memset@plt>
mov    %r14,%rdi
mov    %ebx,%esi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <put_string@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @self_insert_command(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = call i64 (...) @check_editting_mode()
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
br label %45
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* %3
%16 = trunc i32 %15 to i8
store i8 %16, i8* %5
%17 = call i32 @put_string(i8* %5, i32 1)
br label %44
18: ; preds = %11
%19 = load i32, i32* %4
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %43
21: ; preds = %18
%22 = load i32, i32* %4
%23 = call i64 @ck_malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %6
store i32 0, i32* %7
br label %25
25: ; preds = %36, %21
%26 = load i32, i32* %7
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %39
29: ; preds = %25
%30 = load i32, i32* %3
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %6
%33 = load i32, i32* %7
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %36
36: ; preds = %29
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %25
39: ; preds = %25
%40 = load i8*, i8** %6
%41 = load i32, i32* %4
%42 = call i32 @put_string(i8* %40, i32 %41)
br label %43
43: ; preds = %39, %18
br label %44
44: ; preds = %43, %14
br label %45
45: ; preds = %10, %44
ret void
}

LLVM IR (-O2):
define void @self_insert_command(i32 %0, i32 %1) {
%3 = alloca i8
%4 = tail call i64 (...) @check_editting_mode()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = icmp eq i32 %1, 1
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = trunc i32 %0 to i8
store i8 %9, i8* %3
%10 = call i32 @put_string(i8* %3, i32 1)
br label %19
11: ; preds = %6
%12 = icmp sgt i32 %1, 0
br i1 %12, label %13, label %19
13: ; preds = %11
%14 = tail call i64 @ck_malloc(i32 %1)
%15 = inttoptr i64 %14 to i8*
%16 = trunc i32 %0 to i8
%17 = zext i32 %1 to i64
%18 = tail call i32 @put_string(i8* %15, i32 %1)
br label %19
19: ; preds = %8, %13, %11, %2
ret void
}