#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 */
int /*<<< orphan*/ SEEK_CUR;
int atoi(char *);
void *fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
char *malloc(int);
void parse_macro(FILE *in, FILE *out) {
  char *mult_str = malloc(256 * sizeof(char));
  int mult_str_len = 0;
  char cmd;
  int mult;
  int temp_char;
  cmd = fgetc(in);
  fseek(in, 1, SEEK_CUR);
  temp_char = fgetc(in);
  while (temp_char != ')') {
    mult_str[mult_str_len++] = temp_char;
    temp_char = fgetc(in);
  }
  mult_str[mult_str_len] == '\0';
  mult = atoi(mult_str);
  for (int i = 0; i < mult; i++)
    fputc(cmd, out);
  free(mult_str);
}


x86 assembly (clang, -O0):
<parse_macro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x1d(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1070 <fseek@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x29,-0x28(%rbp)
je     11e9 <parse_macro+0x89>
mov    -0x28(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x28(%rbp)
jmp    11b4 <parse_macro+0x54>
mov    -0x18(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1225 <parse_macro+0xc5>
mov    -0x1d(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11fc <parse_macro+0x9c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_macro>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %rax,%r12
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    $0x29,%eax
je     11c4 <parse_macro+0x64>
mov    %r14,%rbp
nopl   0x0(%rax)
mov    %al,0x0(%rbp)
mov    %rbx,%rdi
call   1040 <fgetc@plt>
add    $0x1,%rbp
cmp    $0x29,%eax
jne    11b0 <parse_macro+0x50>
mov    %r14,%rdi
call   1080 <atoi@plt>
test   %eax,%eax
jle    11ef <parse_macro+0x8f>
mov    %eax,%ebx
movsbl %r12b,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
add    $0xffffffff,%ebx
jne    11e0 <parse_macro+0x80>
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define void @parse_macro(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
%11 = call i8* @malloc(i32 256)
store i8* %11, i8** %5
store i32 0, i32* %6
%12 = load i32*, i32** %3
%13 = call i8* @fgetc(i32* %12)
%14 = ptrtoint i8* %13 to i8
store i8 %14, i8* %7
%15 = load i32*, i32** %3
%16 = load i32, i32* @SEEK_CUR
%17 = call i32 @fseek(i32* %15, i32 1, i32 %16)
%18 = load i32*, i32** %3
%19 = call i8* @fgetc(i32* %18)
%20 = ptrtoint i8* %19 to i32
store i32 %20, i32* %9
br label %21
21: ; preds = %24, %2
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 41
br i1 %23, label %24, label %35
24: ; preds = %21
%25 = load i32, i32* %9
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %5
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
%30 = sext i32 %28 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 %26, i8* %31
%32 = load i32*, i32** %3
%33 = call i8* @fgetc(i32* %32)
%34 = ptrtoint i8* %33 to i32
store i32 %34, i32* %9
br label %21
35: ; preds = %21
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 0
%43 = zext i1 %42 to i32
%44 = load i8*, i8** %5
%45 = call i32 @atoi(i8* %44)
store i32 %45, i32* %8
store i32 0, i32* %10
br label %46
46: ; preds = %54, %35
%47 = load i32, i32* %10
%48 = load i32, i32* %8
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %57
50: ; preds = %46
%51 = load i8, i8* %7
%52 = load i32*, i32** %4
%53 = call i32 @fputc(i8 signext %51, i32* %52)
br label %54
54: ; preds = %50
%55 = load i32, i32* %10
%56 = add nsw i32 %55, 1
store i32 %56, i32* %10
br label %46
57: ; preds = %46
%58 = load i8*, i8** %5
%59 = call i32 @free(i8* %58)
ret void
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define void @parse_macro(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%4 = tail call i8* @fgetc(i32* %0)
%5 = ptrtoint i8* %4 to i64
%6 = trunc i64 %5 to i8
%7 = load i32, i32* @SEEK_CUR
%8 = tail call i32 @fseek(i32* %0, i32 1, i32 %7)
%9 = tail call i8* @fgetc(i32* %0)
%10 = ptrtoint i8* %9 to i64
%11 = trunc i64 %10 to i32
%12 = icmp eq i32 %11, 41
br i1 %12, label %23, label %13
13: ; preds = %2, %13
%14 = phi i64 [ %17, %13 ], [ 0, %2 ]
%15 = phi i64 [ %20, %13 ], [ %10, %2 ]
%16 = trunc i64 %15 to i8
%17 = add nuw i64 %14, 1
%18 = getelementptr inbounds i8, i8* %3, i64 %14
store i8 %16, i8* %18
%19 = tail call i8* @fgetc(i32* %0)
%20 = ptrtoint i8* %19 to i64
%21 = trunc i64 %20 to i32
%22 = icmp eq i32 %21, 41
br i1 %22, label %23, label %13
23: ; preds = %13, %2
%24 = tail call i32 @atoi(i8* %3)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %28, %23
%27 = tail call i32 @free(i8* %3)
ret void
28: ; preds = %23, %28
%29 = phi i32 [ %31, %28 ], [ 0, %23 ]
%30 = tail call i32 @fputc(i8 signext %6, i32* %1)
%31 = add nuw nsw i32 %29, 1
%32 = icmp eq i32 %31, %24
br i1 %32, label %26, label %28
}