#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int main(int argc, char *argv[]) {
  char buf[8] = {'\0'};
  char *ptr = NULL;
  printf("%d\n", sizeof(buf) - 1);
  snprintf(buf, sizeof(buf) - 1, "%s", argv[1] ? argv[1] : "zhaixiang");
  printf("%s\n", buf);
  ptr = buf;
  while (*ptr) {
    printf("%c\n", *ptr);
    ptr++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
movq   $0x0,-0x20(%rbp)
lea    0xe9b(%rip),%rdi
mov    $0x7,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1199 <main+0x69>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    11a9 <main+0x79>
lea    0xe67(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11a9 <main+0x79>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x7,%esi
lea    0xe47(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x18(%rbp),%rsi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     120f <main+0xdf>
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11dc <main+0xac>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
movq   $0x0,(%rsp)
lea    0xeba(%rip),%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rbx),%rax
test   %rax,%rax
lea    0xea7(%rip),%rcx
cmovne %rax,%rcx
lea    0xe99(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    (%rsp),%al
test   %al,%al
je     11b8 <main+0x88>
lea    0x1(%rsp),%rbx
lea    0xe7b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11a0 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [10 x i8] c"zhaixiang\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [4 x i8] c"%c\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i8]
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [8 x i8]* %6 to i8*
store i8* null, i8** %7
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 7)
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
br label %20
19: ; preds = %2
br label %20
20: ; preds = %19, %15
%21 = phi i8* [ %18, %15 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %19 ]
%22 = call i32 @snprintf(i8* %10, i32 7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
store i8* %25, i8** %7
br label %26
26: ; preds = %30, %20
%27 = load i8*, i8** %7
%28 = load i8, i8* %27
%29 = icmp ne i8 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %26
%31 = load i8*, i8** %7
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %7
br label %26
37: ; preds = %26
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [10 x i8] c"zhaixiang\00"
@.str.4 = [4 x i8] c"%c\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 7)
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = icmp eq i8* %7, null
%9 = select i1 %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %7
%10 = call i32 @snprintf(i8* %4, i32 7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = call i32 @puts(i8* %4)
%12 = load i8, i8* %4
%13 = icmp eq i8 %12, 0
br i1 %13, label %22, label %14
14: ; preds = %2, %14
%15 = phi i8 [ %20, %14 ], [ %12, %2 ]
%16 = phi i8* [ %19, %14 ], [ %4, %2 ]
%17 = sext i8 %15 to i32
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds i8, i8* %16, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %14
22: ; preds = %14, %2
ret i32 0
}