#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*/ buff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ talking(int /*<<< orphan*/ *, char *, int, float, double);
int main(int argc, char **argv) {
  int x, y;
  char *s;
  char buff[128];
  float f = 5.0;
  double d = 10.0;
  FILE *out = fopen("vararg.out", "w+");
  if (!out) {
    printf("Error %d\n", (int)1);
    exit(1);
  };
  x = 5;
  y = 1;
  s = "hello";
  talking(out, "%d %3.1f %3.1f\n", x, f, d);
  fseek(out, 0, SEEK_SET);
  fread(buff, 1, sizeof(buff) - 1, out);
  fclose(out);
  buff[10] = '\0';
  printf("Should be 5 5.0 10.0: %s\n", buff);
  if (strncmp(buff, "5 5.0 10.0", 10)) {
    printf("Error %d\n", (int)2);
    exit(2);
  };
  {
    printf("Success\n");
    exit(0);
  };
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movss  0xe67(%rip),%xmm0
movss  %xmm0,-0xa4(%rbp)
ff
movsd  0xe4f(%rip),%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
lea    0xe4c(%rip),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
jne    11fe <main+0x7e>
lea    0xe32(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x5,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
lea    0xe11(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0xb8(%rbp),%rdi
mov    -0x14(%rbp),%edx
movss  -0xa4(%rbp),%xmm0
ff
movsd  -0xb0(%rbp),%xmm1
ff
lea    0xdf2(%rip),%rsi
call   1090 <talking@plt>
mov    -0xb8(%rbp),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
lea    -0xa0(%rbp),%rdi
mov    -0xb8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x7f,%edx
call   1040 <fread@plt>
mov    -0xb8(%rbp),%rdi
call   1050 <fclose@plt>
movb   $0x0,-0x96(%rbp)
lea    -0xa0(%rbp),%rsi
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xdad(%rip),%rsi
mov    $0xa,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     12d8 <main+0x158>
lea    0xd58(%rip),%rdi
mov    $0x2,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x88,%rsp
lea    0xe6f(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
jne    11cf <main+0x3f>
lea    0xe65(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    %rax,%rbx
lea    0xe4f(%rip),%rsi
movss  0xe1f(%rip),%xmm0
movsd  0xe1f(%rip),%xmm1
mov    %rax,%rdi
mov    $0x5,%edx
call   10a0 <talking@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x7f,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
movb   $0x0,0xa(%rsp)
lea    0xe03(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe0c(%rip),%rsi
mov    %r14,%rdi
mov    $0xa,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    126b <main+0xdb>
lea    0xdfe(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xdac(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"vararg.out\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [10 x i8] c"Error %d\0A\00"
@.str.3 = [6 x i8] c"hello\00"
@.str.4 = [16 x i8] c"%d %3.1f %3.1f\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [26 x i8] c"Should be 5 5.0 10.0: %s\0A\00"
@.str.6 = [11 x i8] c"5 5.0 10.0\00"
@.str.7 = [9 x i8] c"Success\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [128 x i8]
%10 = alloca float
%11 = alloca double
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store float 5.000000e+00, float* %10
store double 1.000000e+01, double* %11
%13 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %12
%14 = load i32*, i32** %12
%15 = icmp ne i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 1)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
store i32 5, i32* %6
store i32 1, i32* %7
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %8
%20 = load i32*, i32** %12
%21 = load i32, i32* %6
%22 = load float, float* %10
%23 = load double, double* %11
%24 = call i32 @talking(i32* %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %21, float %22, double %23)
%25 = load i32*, i32** %12
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%29 = load i32*, i32** %12
%30 = call i32 @fread(i8* %28, i32 1, i32 127, i32* %29)
%31 = load i32*, i32** %12
%32 = call i32 @fclose(i32* %31)
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 10
store i8 0, i8* %33
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %34)
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%37 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 10)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %19
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 2)
%41 = call i32 @exit(i32 2)
unreachable
42: ; preds = %19
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%44 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"vararg.out\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [10 x i8] c"Error %d\0A\00"
@.str.4 = [16 x i8] c"%d %3.1f %3.1f\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [26 x i8] c"Should be 5 5.0 10.0: %s\0A\00"
@.str.6 = [11 x i8] c"5 5.0 10.0\00"
@str = [8 x i8] c"Success\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 1)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = tail call i32 @talking(i32* %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 5, float 5.000000e+00, double 1.000000e+01)
%12 = load i32, i32* @SEEK_SET
%13 = tail call i32 @fseek(i32* %5, i32 0, i32 %12)
%14 = call i32 @fread(i8* %4, i32 1, i32 127, i32* %5)
%15 = tail call i32 @fclose(i32* %5)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 10
store i8 0, i8* %16
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%18 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 10)
%19 = icmp eq i64 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %10
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 2)
%22 = call i32 @exit(i32 2)
unreachable
23: ; preds = %10
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
}