#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 /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char, int, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
void print_balken(char c, int num, char *nformat, int zahl) {
  char *p = malloc((num + 1) * sizeof(char));
  char format_buf[20];
  memset(p, '#', num * sizeof(char));
  p[num] = '\0';
  snprintf(format_buf, 20, "%%c %s %%s\n", nformat);
  printf(format_buf, c, zahl == -1 ? num : zahl, p);
  free(p);
}


x86 assembly (clang, -O0):
<print_balken>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
mov    $0x23,%esi
call   1060 <memset@plt>
mov    -0x20(%rbp),%rax
movslq -0x8(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x14,%esi
lea    0xe49(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x1(%rbp),%al
mov    %al,-0x41(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11df <print_balken+0x8f>
mov    -0x8(%rbp),%eax
mov    %eax,-0x54(%rbp)
jmp    11e5 <print_balken+0x95>
mov    -0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x41(%rbp),%al
mov    -0x50(%rbp),%rdi
mov    -0x54(%rbp),%edx
mov    -0x20(%rbp),%rcx
movsbl %al,%esi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_balken>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %esi,%ebx
mov    %edi,%r14d
lea    0x1(%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
movslq %ebx,%rbx
mov    %rax,%rdi
mov    $0x23,%esi
mov    %ebx,%edx
call   1060 <memset@plt>
movb   $0x0,0x0(%rbp,%rbx,1)
lea    0xe6e(%rip),%rdx
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x14,%esi
mov    %r15,%rcx
call   1050 <snprintf@plt>
cmp    $0xffffffff,%r12d
cmove  %ebx,%r12d
mov    %r13,%rdi
mov    %r14d,%esi
mov    %r12d,%edx
mov    %rbp,%rcx
call   1040 <printf@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%%c %s %%s\0A\00"
define void @print_balken(i8 signext %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca [20 x i8]
store i8 %0, i8* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i8* @malloc(i32 %15)
store i8* %16, i8** %9
%17 = load i8*, i8** %9
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i32 @memset(i8* %17, i8 signext 35, i32 %21)
%23 = load i8*, i8** %9
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 0, i8* %26
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%28 = load i8*, i8** %7
%29 = call i32 @snprintf(i8* %27, i32 20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%31 = load i8, i8* %5
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %4
%35 = load i32, i32* %6
br label %38
36: ; preds = %4
%37 = load i32, i32* %8
br label %38
38: ; preds = %36, %34
%39 = phi i32 [ %35, %34 ], [ %37, %36 ]
%40 = load i8*, i8** %9
%41 = call i32 @printf(i8* %30, i8 signext %31, i32 %39, i8* %40)
%42 = load i8*, i8** %9
%43 = call i32 @free(i8* %42)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"%%c %s %%s\0A\00"
define void @print_balken(i8 signext %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [20 x i8]
%6 = add nsw i32 %1, 1
%7 = tail call i8* @malloc(i32 %6)
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%9 = sext i32 %1 to i64
%10 = tail call i32 @memset(i8* %7, i8 signext 35, i32 %1)
%11 = getelementptr inbounds i8, i8* %7, i64 %9
store i8 0, i8* %11
%12 = call i32 @snprintf(i8* %8, i32 20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2)
%13 = icmp eq i32 %3, -1
%14 = select i1 %13, i32 %1, i32 %3
%15 = call i32 @printf(i8* %8, i8 signext %0, i32 %14, i8* %7)
%16 = call i32 @free(i8* %7)
ret void
}