#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*/ O_RDONLY;
int /*<<< orphan*/ open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  char s[] = "foobar";
  int i = 1247;
  unsigned x = 0x123ABC;
  long l = 12345678;
  unsigned long lx = 0x12345678;
  void *ptr = (void *)0x11223344;
  printf("non-format string\n");
  printf("str: %s\n", s);
  printf("int: %i\n", i);
  printf("long: %li\n", l);
  printf("hex: 0x%08X\n", x);
  printf("long hex: 0x%lX\n", lx);
  printf("pointer: 0x%p\n", ptr);
  open("nonexistant", O_RDONLY);
  printf("error: %m\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xec4(%rip),%eax
mov    %eax,-0x17(%rbp)
mov    0xebe(%rip),%ax
mov    %ax,-0x13(%rbp)
mov    0xeb6(%rip),%al
mov    %al,-0x11(%rbp)
movl   $0x4df,-0x1c(%rbp)
movl   $0x123abc,-0x20(%rbp)
movq   $0xbc614e,-0x28(%rbp)
movq   $0x12345678,-0x30(%rbp)
12
mov    $0x11223344,%eax
mov    %rax,-0x38(%rbp)
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x17(%rbp),%rsi
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%esi
lea    0xe7f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1040 <open@plt>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
movl   $0x726162,0x3(%rsp)
movl   $0x626f6f66,(%rsp)
lea    0xf21(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb4(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
mov    $0x4df,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea2(%rip),%rdi
mov    $0xbc614e,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9a(%rip),%rdi
mov    $0x123abc,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe94(%rip),%rdi
mov    $0x12345678,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe92(%rip),%rdi
mov    $0x11223344,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
lea    0xe85(%rip),%rdi
call   1050 <open@plt>
lea    0xe85(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@__const.main.s = [7 x i8] c"foobar\00"
@.str = [19 x i8] c"non-format string\0A\00"
@.str.1 = [9 x i8] c"str: %s\0A\00"
@.str.2 = [9 x i8] c"int: %i\0A\00"
@.str.3 = [11 x i8] c"long: %li\0A\00"
@.str.4 = [13 x i8] c"hex: 0x%08X\0A\00"
@.str.5 = [17 x i8] c"long hex: 0x%lX\0A\00"
@.str.6 = [15 x i8] c"pointer: 0x%p\0A\00"
@.str.7 = [12 x i8] c"nonexistant\00"
@O_RDONLY = global i32 0
@.str.8 = [11 x i8] c"error: %m\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [7 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [7 x i8]* %6 to i8*
store i32 1247, i32* %7
store i32 1194684, i32* %8
store i64 12345678, i64* %9
store i64 305419896, i64* %10
store i8* inttoptr (i64 287454020 to i8*), i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i32, i32* %7
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %16)
%18 = load i64, i64* %9
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 %18)
%20 = load i32, i32* %8
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = load i64, i64* %10
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 %22)
%24 = load i8*, i8** %11
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @O_RDONLY
%27 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@__const.main.s = [7 x i8] c"foobar\00"
@.str.1 = [9 x i8] c"str: %s\0A\00"
@.str.2 = [9 x i8] c"int: %i\0A\00"
@.str.3 = [11 x i8] c"long: %li\0A\00"
@.str.4 = [13 x i8] c"hex: 0x%08X\0A\00"
@.str.5 = [17 x i8] c"long hex: 0x%lX\0A\00"
@.str.6 = [15 x i8] c"pointer: 0x%p\0A\00"
@.str.7 = [12 x i8] c"nonexistant\00"
@O_RDONLY = global i32 0
@.str.8 = [11 x i8] c"error: %m\0A\00"
@str = [18 x i8] c"non-format string\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [7 x i8]
%4 = getelementptr inbounds [7 x i8], [7 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 1247)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i64 12345678)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i32 1194684)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 305419896)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i8* inttoptr (i64 287454020 to i8*))
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}