#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ output(char, unsigned long *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp = fopen("input", "r");
  char d;
  unsigned long ol = 0;
  int i, j, arg1, arg2;
  if (fp == NULL) {
    printf("could not open input file\n");
    return -1;
  }
  while (fscanf(fp, "%c", &d) != EOF) {
    if (d == '(') {
      fscanf(fp, "%ix%i)", &arg1, &arg2);
      char temp[128];
      fgets(temp, arg1 + 1, fp);
      for (i = 0; i < arg2; i++) {
        for (j = 0; j < arg1; j++) {
          output(temp[j], &ol);
        }
      }
    } else {
      output(d, &ol);
    }
  }
  printf("\nWe output %lu chars.\n", ol);
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b6 <main+0x56>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b3 <main+0x153>
jmp    11bb <main+0x5b>
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
lea    -0x11(%rbp),%rdx
mov    $0x0,%al
call   1060 <fscanf@plt>
mov    0x2e10(%rip),%rcx
cmp    (%rcx),%rax
je     1291 <main+0x131>
movsbl -0x11(%rbp),%eax
cmp    $0x28,%eax
jne    127f <main+0x11f>
mov    -0x10(%rbp),%rdi
lea    0xe2d(%rip),%rsi
lea    -0x2c(%rbp),%rdx
lea    -0x30(%rbp),%rcx
mov    $0x0,%al
call   1060 <fscanf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rdx
call   1070 <fgets@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    127a <main+0x11a>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1267 <main+0x107>
movslq -0x28(%rbp),%rax
lea    -0x20(%rbp),%rsi
movsbl -0xb0(%rbp,%rax,1),%edi
ff
call   1030 <output@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1238 <main+0xd8>
jmp    126c <main+0x10c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1225 <main+0xc5>
jmp    128c <main+0x12c>
lea    -0x20(%rbp),%rsi
movsbl -0x11(%rbp),%edi
call   1030 <output@plt>
jmp    11bb <main+0x5b>
mov    -0x20(%rbp),%rsi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
lea    0xe78(%rip),%rdi
lea    0xe77(%rip),%rsi
call   1090 <fopen@plt>
movq   $0x0,0x18(%rsp)
test   %rax,%rax
je     11d1 <main+0x61>
mov    %rax,%r13
lea    0xe5c(%rip),%rsi
xor    %ebp,%ebp
lea    0xf(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    0x2e24(%rip),%r12
cmp    (%r12),%rax
jne    11e7 <main+0x77>
xor    %esi,%esi
jmp    12c4 <main+0x154>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
jmp    12da <main+0x16a>
lea    0x18(%rsp),%r14
lea    0xe15(%rip),%rbp
lea    0xf(%rsp),%rbx
jmp    1225 <main+0xb5>
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r14,%rsi
call   1040 <output@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fscanf@plt>
cmp    (%r12),%rax
je     12bd <main+0x14d>
mov    0xf(%rsp),%al
cmp    $0x28,%al
jne    1200 <main+0x90>
mov    %rbp,%rbx
mov    %r13,%rdi
lea    0xdd1(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x14(%rsp),%rcx
xor    %eax,%eax
call   1070 <fscanf@plt>
mov    0x10(%rsp),%esi
add    $0x1,%esi
lea    0x20(%rsp),%rdi
mov    %r13,%rdx
call   1080 <fgets@plt>
mov    0x14(%rsp),%ecx
test   %ecx,%ecx
jle    12b0 <main+0x140>
xor    %ebp,%ebp
mov    0x10(%rsp),%eax
jmp    1277 <main+0x107>
nop
add    $0x1,%ebp
cmp    %ecx,%ebp
jge    12b0 <main+0x140>
test   %eax,%eax
jle    1270 <main+0x100>
xor    %r15d,%r15d
xchg   %ax,%ax
movsbl 0x20(%rsp,%r15,1),%edi
mov    %r14,%rsi
call   1040 <output@plt>
add    $0x1,%r15
movslq 0x10(%rsp),%rax
cmp    %rax,%r15
jl     1280 <main+0x110>
mov    0x14(%rsp),%ecx
jmp    1270 <main+0x100>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rbp
lea    0xf(%rsp),%rbx
jmp    120b <main+0x9b>
mov    0x18(%rsp),%rsi
xor    %ebp,%ebp
lea    0xd47(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
mov    %ebp,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"could not open input file\0A\00"
@.str.3 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.4 = [7 x i8] c"%ix%i)\00"
@.str.5 = [23 x i8] c"\0AWe output %lu chars.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [128 x i8]
store i32 0, i32* %1
%10 = call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %2
store i64 0, i64* %4
%11 = load i32*, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %65
15: ; preds = %0
br label %16
16: ; preds = %59, %15
%17 = load i32*, i32** %2
%18 = call i64 (i32*, i8*, ...) @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%19 = load i64, i64* @EOF
%20 = icmp ne i64 %18, %19
br i1 %20, label %21, label %60
21: ; preds = %16
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 40
br i1 %24, label %25, label %56
25: ; preds = %21
%26 = load i32*, i32** %2
%27 = call i64 (i32*, i8*, ...) @fscanf(i32* %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %7, i32* %8)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
%31 = load i32*, i32** %2
%32 = call i32 @fgets(i8* %28, i32 %30, i32* %31)
store i32 0, i32* %5
br label %33
33: ; preds = %52, %25
%34 = load i32, i32* %5
%35 = load i32, i32* %8
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %55
37: ; preds = %33
store i32 0, i32* %6
br label %38
38: ; preds = %48, %37
%39 = load i32, i32* %6
%40 = load i32, i32* %7
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %51
42: ; preds = %38
%43 = load i32, i32* %6
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @output(i8 signext %46, i64* %4)
br label %48
48: ; preds = %42
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %38
51: ; preds = %38
br label %52
52: ; preds = %51
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %33
55: ; preds = %33
br label %59
56: ; preds = %21
%57 = load i8, i8* %3
%58 = call i32 @output(i8 signext %57, i64* %4)
br label %59
59: ; preds = %56, %55
br label %16
60: ; preds = %16
%61 = load i64, i64* %4
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %61)
%63 = load i32*, i32** %2
%64 = call i32 @fclose(i32* %63)
store i32 0, i32* %1
br label %65
65: ; preds = %60, %13
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@.str = [6 x i8] c"input\00"
@.str.1 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%c\00"
@EOF = global i64 0
@.str.4 = [7 x i8] c"%ix%i)\00"
@.str.5 = [23 x i8] c"\0AWe output %lu chars.\0A\00"
@str = [26 x i8] c"could not open input file\00"
define i32 @main() {
%1 = alloca i8
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%8 = bitcast i32* %3 to i8*
%9 = bitcast i32* %4 to i8*
%10 = icmp eq i32* %6, null
br i1 %10, label %17, label %11
11: ; preds = %0
%12 = call i64 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%13 = load i64, i64* @EOF
%14 = icmp eq i64 %12, %13
br i1 %14, label %61, label %15
15: ; preds = %11
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
br label %19
17: ; preds = %0
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %65
19: ; preds = %15, %55
%20 = load i8, i8* %1
%21 = icmp eq i8 %20, 40
br i1 %21, label %22, label %53
22: ; preds = %19
%23 = call i64 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %3, i32* %4)
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
%26 = call i32 @fgets(i8* %16, i32 %25, i32* %6)
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %52
29: ; preds = %22
%30 = load i32, i32* %3
br label %31
31: ; preds = %29, %47
%32 = phi i32 [ %48, %47 ], [ %27, %29 ]
%33 = phi i32 [ %49, %47 ], [ %30, %29 ]
%34 = phi i32 [ %50, %47 ], [ 0, %29 ]
%35 = icmp sgt i32 %33, 0
br i1 %35, label %36, label %47
36: ; preds = %31, %36
%37 = phi i64 [ %41, %36 ], [ 0, %31 ]
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @output(i8 signext %39, i64* %2)
%41 = add nuw nsw i64 %37, 1
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = icmp slt i64 %41, %43
br i1 %44, label %36, label %45
45: ; preds = %36
%46 = load i32, i32* %4
br label %47
47: ; preds = %45, %31
%48 = phi i32 [ %46, %45 ], [ %32, %31 ]
%49 = phi i32 [ %42, %45 ], [ %33, %31 ]
%50 = add nuw nsw i32 %34, 1
%51 = icmp slt i32 %50, %48
br i1 %51, label %31, label %52
52: ; preds = %47, %22
br label %55
53: ; preds = %19
%54 = call i32 @output(i8 signext %20, i64* %2)
br label %55
55: ; preds = %53, %52
%56 = call i64 (i32*, i8*, ...) @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%57 = load i64, i64* @EOF
%58 = icmp eq i64 %56, %57
br i1 %58, label %59, label %19
59: ; preds = %55
%60 = load i64, i64* %2
br label %61
61: ; preds = %59, %11
%62 = phi i64 [ %60, %59 ], [ 0, %11 ]
%63 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i64 %62)
%64 = call i32 @fclose(i32* %6)
br label %65
65: ; preds = %61, %17
%66 = phi i32 [ -1, %17 ], [ 0, %61 ]
ret i32 %66
}