#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 O_CREAT;
int O_RDWR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char const *, int, int);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned int, unsigned int,
                          unsigned int);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
unsigned int strtoul(char *, char **, int);
int write(int, unsigned char *, int);
void create_partition_table(const char *filename, char *format) {
  unsigned char buf[512], *entry;
  unsigned pindex, offset;
  int fd, activated = 0;
  memset(buf, 0, sizeof(buf));
  buf[510] = 0x55;
  buf[511] = 0xaa;
  offset = 2;
  char *p = strtok(format, ":");
  for (pindex = 1; p && pindex <= 4; pindex++) {
    char *q, *endptr;
    unsigned type, len;
    q = strchr(p, '=');
    if (!q) {
      fprintf(stderr, "%s: wrong format '%s' for partition %u\n", filename, p,
              pindex);
      exit(-1);
    }
    *q++ = 0;
    len = strtoul(q, &endptr, 0);
    if (*endptr == 'k')
      len *= 2;
    else if (*endptr == 'm' || *endptr == 'M')
      len *= 2 * 1024;
    else if (*endptr != '\0') {
      fprintf(stderr, "%s: wrong length '%s' for partition %u\n", filename, q,
              pindex);
      exit(-1);
    }
    if (strcmp(p, "fs") == 0)
      type = 0xb7;
    else if (strcmp(p, "swap") == 0)
      type = 0xb8;
    else {
      type = strtoul(p, &endptr, 16);
      if (*endptr != '\0') {
        fprintf(stderr, "%s: wrong type '%s' for partition %u\n", filename, p,
                pindex);
        exit(-1);
      }
    }
    printf("Allocated partition %u, type %02x, start %u, size %u sectors\n",
           pindex, type, offset, len);
    entry = &buf[446 + (pindex - 1) * 16];
    entry[4] = type;
    *(unsigned *)&entry[8] = offset;
    *(unsigned *)&entry[12] = len;
    if (type == 0xb7 && !activated) {
      entry[0] = 0x80;
      activated = 1;
    }
    p = strtok(NULL, ":");
    offset += len;
  }
  fd = open(filename, O_CREAT | O_RDWR, 0666);
  if (fd < 0) {
    fprintf(stderr, "%s: cannot create file\n", filename);
    exit(-1);
  }
  if (write(fd, buf, 512) != 512) {
    fprintf(stderr, "%s: error writing partition table\n", filename);
    exit(-1);
  }
}


x86 assembly (clang, -O0):
<create_partition_table>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x228(%rbp)
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
movb   $0x55,-0x12(%rbp)
movb   $0xaa,-0x11(%rbp)
movl   $0x2,-0x220(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe13(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x230(%rbp)
movl   $0x1,-0x21c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x230(%rbp)
mov    %al,-0x249(%rbp)
je     1229 <create_partition_table+0x89>
cmpl   $0x4,-0x21c(%rbp)
setbe  %al
mov    %al,-0x249(%rbp)
mov    -0x249(%rbp),%al
test   $0x1,%al
jne    123c <create_partition_table+0x9c>
jmp    152a <create_partition_table+0x38a>
mov    -0x230(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x238(%rbp)
cmpq   $0x0,-0x238(%rbp)
jne    1295 <create_partition_table+0xf5>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x230(%rbp),%rcx
mov    -0x21c(%rbp),%r8d
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x238(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x238(%rbp)
movb   $0x0,(%rax)
mov    -0x238(%rbp),%rdi
lea    -0x240(%rbp),%rsi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %eax,-0x248(%rbp)
mov    -0x240(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6b,%eax
jne    12ef <create_partition_table+0x14f>
mov    -0x248(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x248(%rbp)
jmp    1379 <create_partition_table+0x1d9>
mov    -0x240(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6d,%eax
je     1315 <create_partition_table+0x175>
mov    -0x240(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4d,%eax
jne    1329 <create_partition_table+0x189>
mov    -0x248(%rbp),%eax
shl    $0xb,%eax
mov    %eax,-0x248(%rbp)
jmp    1374 <create_partition_table+0x1d4>
mov    -0x240(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     136f <create_partition_table+0x1cf>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x238(%rbp),%rcx
mov    -0x21c(%rbp),%r8d
lea    0xccc(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
jmp    1374 <create_partition_table+0x1d4>
jmp    1379 <create_partition_table+0x1d9>
mov    -0x230(%rbp),%rdi
lea    0xccb(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    13a5 <create_partition_table+0x205>
movl   $0xb7,-0x244(%rbp)
jmp    143f <create_partition_table+0x29f>
mov    -0x230(%rbp),%rdi
lea    0xca2(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    13d1 <create_partition_table+0x231>
movl   $0xb8,-0x244(%rbp)
jmp    143a <create_partition_table+0x29a>
mov    -0x230(%rbp),%rdi
lea    -0x240(%rbp),%rsi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,-0x244(%rbp)
mov    -0x240(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1435 <create_partition_table+0x295>
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x230(%rbp),%rcx
mov    -0x21c(%rbp),%r8d
lea    0xc36(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
jmp    143a <create_partition_table+0x29a>
jmp    143f <create_partition_table+0x29f>
mov    -0x21c(%rbp),%esi
mov    -0x244(%rbp),%edx
mov    -0x220(%rbp),%ecx
mov    -0x248(%rbp),%r8d
lea    0xc21(%rip),%rdi
call   1050 <printf@plt>
mov    -0x21c(%rbp),%eax
sub    $0x1,%eax
shl    $0x4,%eax
add    $0x1be,%eax
mov    %eax,%eax
mov    %eax,%ecx
lea    -0x210(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x218(%rbp)
mov    -0x244(%rbp),%eax
mov    %al,%cl
mov    -0x218(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x220(%rbp),%ecx
mov    -0x218(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x248(%rbp),%ecx
mov    -0x218(%rbp),%rax
mov    %ecx,0xc(%rax)
cmpl   $0xb7,-0x244(%rbp)
jne    14ed <create_partition_table+0x34d>
cmpl   $0x0,-0x228(%rbp)
jne    14ed <create_partition_table+0x34d>
mov    -0x218(%rbp),%rax
movb   $0x80,(%rax)
movl   $0x1,-0x228(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xb08(%rip),%rsi
call   10a0 <strtok@plt>
mov    %rax,-0x230(%rbp)
mov    -0x248(%rbp),%eax
add    -0x220(%rbp),%eax
mov    %eax,-0x220(%rbp)
mov    -0x21c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x21c(%rbp)
jmp    1203 <create_partition_table+0x63>
mov    -0x8(%rbp),%rdi
mov    0x2ac3(%rip),%rax
mov    (%rax),%esi
mov    0x2aa2(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1090 <open@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x0,-0x224(%rbp)
jge    1582 <create_partition_table+0x3e2>
mov    0x2a6c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xb4d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    -0x224(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
cmp    $0x200,%eax
je     15c9 <create_partition_table+0x429>
mov    0x2a25(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xb1e(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_partition_table>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x228,%rsp
mov    %rsi,%rbx
mov    %rdi,(%rsp)
lea    0x20(%rsp),%rdi
xor    %eax,%eax
mov    %rax,0x18(%rsp)
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
movw   $0xaa55,0x21e(%rsp)
lea    0xe1f(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <strtok@plt>
test   %rax,%rax
je     135f <create_partition_table+0x1bf>
mov    %rax,%r12
lea    0x1ea(%rsp),%r15
mov    $0x2,%ebp
mov    $0x1,%eax
nopw   0x0(%rax,%rax,1)
mov    %rax,0x8(%rsp)
mov    %r12,%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     13b8 <create_partition_table+0x218>
mov    %rax,%r14
add    $0x1,%r14
movb   $0x0,(%rax)
mov    %r14,%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   10b0 <strtoul@plt>
mov    %eax,%r13d
mov    0x10(%rsp),%rax
movzbl (%rax),%eax
cmp    $0x6a,%al
jg     1260 <create_partition_table+0xc0>
test   %al,%al
je     1284 <create_partition_table+0xe4>
cmp    $0x4d,%al
je     1280 <create_partition_table+0xe0>
jmp    13ed <create_partition_table+0x24d>
cmp    $0x6d,%al
je     1280 <create_partition_table+0xe0>
cmp    $0x6b,%al
jne    13ed <create_partition_table+0x24d>
add    %r13d,%r13d
jmp    1284 <create_partition_table+0xe4>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
shl    $0xb,%r13d
mov    %r12,%rdi
lea    0xdc4(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12e0 <create_partition_table+0x140>
mov    %r12,%rdi
lea    0xdb3(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
mov    0x8(%rsp),%r14
je     12f0 <create_partition_table+0x150>
mov    %r12,%rdi
lea    0x10(%rsp),%rsi
mov    $0x10,%edx
call   10b0 <strtoul@plt>
mov    %eax,%ebx
mov    0x10(%rsp),%rax
cmpb   $0x0,(%rax)
je     12f5 <create_partition_table+0x155>
jmp    13d1 <create_partition_table+0x231>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0xb7,%ebx
mov    0x8(%rsp),%r14
jmp    12f5 <create_partition_table+0x155>
nopl   0x0(%rax)
mov    $0xb8,%ebx
lea    0xd84(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
mov    %r13d,%r8d
call   1050 <printf@plt>
mov    %bl,-0x8(%r15)
mov    %ebp,-0x4(%r15)
mov    %r13d,(%r15)
cmp    $0xb7,%ebx
jne    1334 <create_partition_table+0x194>
cmpl   $0x0,0x18(%rsp)
jne    1334 <create_partition_table+0x194>
movb   $0x80,-0xc(%r15)
mov    $0x1,%eax
mov    %rax,0x18(%rsp)
xor    %edi,%edi
lea    0xcc3(%rip),%rsi
call   10a0 <strtok@plt>
test   %rax,%rax
je     135f <create_partition_table+0x1bf>
mov    %rax,%r12
add    %r13d,%ebp
lea    0x1(%r14),%rax
add    $0x10,%r15
cmp    $0x4,%r14
jb     1210 <create_partition_table+0x70>
mov    0x2c92(%rip),%rax
mov    0x2c73(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    (%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1090 <open@plt>
test   %eax,%eax
js     141a <create_partition_table+0x27a>
lea    0x20(%rsp),%rsi
mov    %eax,%edi
mov    $0x200,%edx
call   1030 <write@plt>
cmp    $0x200,%eax
jne    142c <create_partition_table+0x28c>
add    $0x228,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
lea    0xc3a(%rip),%rsi
mov    (%rsp),%rdx
mov    %r12,%rcx
jmp    1404 <create_partition_table+0x264>
mov    0x2bf8(%rip),%rax
mov    (%rax),%edi
lea    0xc79(%rip),%rsi
mov    (%rsp),%rdx
mov    %r12,%rcx
mov    %r14d,%r8d
jmp    1409 <create_partition_table+0x269>
mov    0x2bdc(%rip),%rax
mov    (%rax),%edi
lea    0xc2d(%rip),%rsi
mov    (%rsp),%rdx
mov    %r14,%rcx
mov    0x8(%rsp),%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    0x2baf(%rip),%rax
mov    (%rax),%edi
lea    0xc94(%rip),%rsi
jmp    143c <create_partition_table+0x29c>
mov    0x2b9d(%rip),%rax
mov    (%rax),%edi
lea    0xc9a(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"%s: wrong format '%s' for partition %u\0A\00"
@.str.2 = [40 x i8] c"%s: wrong length '%s' for partition %u\0A\00"
@.str.3 = [3 x i8] c"fs\00"
@.str.4 = [5 x i8] c"swap\00"
@.str.5 = [38 x i8] c"%s: wrong type '%s' for partition %u\0A\00"
@.str.6 = [62 x i8] c"Allocated partition %u, type %02x, start %u, size %u sectors\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.7 = [24 x i8] c"%s: cannot create file\0A\00"
@.str.8 = [35 x i8] c"%s: error writing partition table\0A\00"
define void @create_partition_table(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [512 x i8]
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %10
%16 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%17 = call i32 @memset(i8* %16, i32 0, i32 512)
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 510
store i8 85, i8* %18
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 511
store i8 -86, i8* %19
store i32 2, i32* %8
%20 = load i8*, i8** %4
%21 = call i8* @strtok(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %11
store i32 1, i32* %7
br label %22
22: ; preds = %144, %2
%23 = load i8*, i8** %11
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* %7
%27 = icmp ule i32 %26, 4
br label %28
28: ; preds = %25, %22
%29 = phi i1 [ false, %22 ], [ %27, %25 ]
br i1 %29, label %30, label %147
30: ; preds = %28
%31 = load i8*, i8** %11
%32 = call i8* @strchr(i8* %31, i8 signext 61)
store i8* %32, i8** %12
%33 = load i8*, i8** %12
%34 = icmp ne i8* %33, null
br i1 %34, label %42, label %35
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %3
%38 = load i8*, i8** %11
%39 = load i32, i32* %7
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %38, i32 %39)
%41 = call i32 @exit(i32 -1)
unreachable
42: ; preds = %30
%43 = load i8*, i8** %12
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %12
store i8 0, i8* %43
%45 = load i8*, i8** %12
%46 = call i32 @strtoul(i8* %45, i8** %13, i32 0)
store i32 %46, i32* %15
%47 = load i8*, i8** %13
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 107
br i1 %50, label %51, label %54
51: ; preds = %42
%52 = load i32, i32* %15
%53 = mul i32 %52, 2
store i32 %53, i32* %15
br label %81
54: ; preds = %42
%55 = load i8*, i8** %13
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 109
br i1 %58, label %64, label %59
59: ; preds = %54
%60 = load i8*, i8** %13
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 77
br i1 %63, label %64, label %67
64: ; preds = %59, %54
%65 = load i32, i32* %15
%66 = mul i32 %65, 2048
store i32 %66, i32* %15
br label %80
67: ; preds = %59
%68 = load i8*, i8** %13
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %79
72: ; preds = %67
%73 = load i32, i32* @stderr
%74 = load i8*, i8** %3
%75 = load i8*, i8** %12
%76 = load i32, i32* %7
%77 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %74, i8* %75, i32 %76)
%78 = call i32 @exit(i32 -1)
unreachable
79: ; preds = %67
br label %80
80: ; preds = %79, %64
br label %81
81: ; preds = %80, %51
%82 = load i8*, i8** %11
%83 = call i64 @strcmp(i8* %82, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%84 = icmp eq i64 %83, 0
br i1 %84, label %85, label %86
85: ; preds = %81
store i32 183, i32* %14
br label %107
86: ; preds = %81
%87 = load i8*, i8** %11
%88 = call i64 @strcmp(i8* %87, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%89 = icmp eq i64 %88, 0
br i1 %89, label %90, label %91
90: ; preds = %86
store i32 184, i32* %14
br label %106
91: ; preds = %86
%92 = load i8*, i8** %11
%93 = call i32 @strtoul(i8* %92, i8** %13, i32 16)
store i32 %93, i32* %14
%94 = load i8*, i8** %13
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = icmp ne i32 %96, 0
br i1 %97, label %98, label %105
98: ; preds = %91
%99 = load i32, i32* @stderr
%100 = load i8*, i8** %3
%101 = load i8*, i8** %11
%102 = load i32, i32* %7
%103 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %100, i8* %101, i32 %102)
%104 = call i32 @exit(i32 -1)
unreachable
105: ; preds = %91
br label %106
106: ; preds = %105, %90
br label %107
107: ; preds = %106, %85
%108 = load i32, i32* %7
%109 = load i32, i32* %14
%110 = load i32, i32* %8
%111 = load i32, i32* %15
%112 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0), i32 %108, i32 %109, i32 %110, i32 %111)
%113 = load i32, i32* %7
%114 = sub i32 %113, 1
%115 = mul i32 %114, 16
%116 = add i32 446, %115
%117 = zext i32 %116 to i64
%118 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 %117
store i8* %118, i8** %6
%119 = load i32, i32* %14
%120 = trunc i32 %119 to i8
%121 = load i8*, i8** %6
%122 = getelementptr inbounds i8, i8* %121, i64 4
store i8 %120, i8* %122
%123 = load i32, i32* %8
%124 = load i8*, i8** %6
%125 = getelementptr inbounds i8, i8* %124, i64 8
%126 = bitcast i8* %125 to i32*
store i32 %123, i32* %126
%127 = load i32, i32* %15
%128 = load i8*, i8** %6
%129 = getelementptr inbounds i8, i8* %128, i64 12
%130 = bitcast i8* %129 to i32*
store i32 %127, i32* %130
%131 = load i32, i32* %14
%132 = icmp eq i32 %131, 183
br i1 %132, label %133, label %139
133: ; preds = %107
%134 = load i32, i32* %10
%135 = icmp ne i32 %134, 0
br i1 %135, label %139, label %136
136: ; preds = %133
%137 = load i8*, i8** %6
%138 = getelementptr inbounds i8, i8* %137, i64 0
store i8 -128, i8* %138
store i32 1, i32* %10
br label %139
139: ; preds = %136, %133, %107
%140 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %140, i8** %11
%141 = load i32, i32* %15
%142 = load i32, i32* %8
%143 = add i32 %142, %141
store i32 %143, i32* %8
br label %144
144: ; preds = %139
%145 = load i32, i32* %7
%146 = add i32 %145, 1
store i32 %146, i32* %7
br label %22
147: ; preds = %28
%148 = load i8*, i8** %3
%149 = load i32, i32* @O_CREAT
%150 = load i32, i32* @O_RDWR
%151 = or i32 %149, %150
%152 = call i32 @open(i8* %148, i32 %151, i32 438)
store i32 %152, i32* %9
%153 = load i32, i32* %9
%154 = icmp slt i32 %153, 0
br i1 %154, label %155, label %160
155: ; preds = %147
%156 = load i32, i32* @stderr
%157 = load i8*, i8** %3
%158 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %156, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %157)
%159 = call i32 @exit(i32 -1)
unreachable
160: ; preds = %147
%161 = load i32, i32* %9
%162 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%163 = call i32 @write(i32 %161, i8* %162, i32 512)
%164 = icmp ne i32 %163, 512
br i1 %164, label %165, label %170
165: ; preds = %160
%166 = load i32, i32* @stderr
%167 = load i8*, i8** %3
%168 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %166, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %167)
%169 = call i32 @exit(i32 -1)
unreachable
170: ; preds = %160
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"%s: wrong format '%s' for partition %u\0A\00"
@.str.2 = [40 x i8] c"%s: wrong length '%s' for partition %u\0A\00"
@.str.3 = [3 x i8] c"fs\00"
@.str.4 = [5 x i8] c"swap\00"
@.str.5 = [38 x i8] c"%s: wrong type '%s' for partition %u\0A\00"
@.str.6 = [62 x i8] c"Allocated partition %u, type %02x, start %u, size %u sectors\0A\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.7 = [24 x i8] c"%s: cannot create file\0A\00"
@.str.8 = [35 x i8] c"%s: error writing partition table\0A\00"
define void @create_partition_table(i8* %0, i8* %1) {
%3 = alloca [512 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 512)
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 510
store i8 85, i8* %7
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 511
store i8 -86, i8* %8
%9 = call i8* @strtok(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %81, label %11
11: ; preds = %2
%12 = bitcast i8** %4 to i8*
br label %13
13: ; preds = %11, %73
%14 = phi i64 [ 1, %11 ], [ %77, %73 ]
%15 = phi i8* [ %9, %11 ], [ %75, %73 ]
%16 = phi i32 [ 0, %11 ], [ %74, %73 ]
%17 = phi i32 [ 2, %11 ], [ %76, %73 ]
%18 = call i8* @strchr(i8* %15, i8 signext 61)
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %13
%21 = trunc i64 %14 to i32
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %15, i32 %21)
%24 = call i32 @exit(i32 -1)
unreachable
25: ; preds = %13
%26 = getelementptr inbounds i8, i8* %18, i64 1
store i8 0, i8* %18
%27 = call i32 @strtoul(i8* %26, i8** %4, i32 0)
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
switch i8 %29, label %34 [
i8 107, label %30
i8 109, label %32
i8 77, label %32
i8 0, label %39
]
30: ; preds = %25
%31 = shl i32 %27, 1
br label %39
32: ; preds = %25, %25
%33 = shl i32 %27, 11
br label %39
34: ; preds = %25
%35 = trunc i64 %14 to i32
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %26, i32 %35)
%38 = call i32 @exit(i32 -1)
unreachable
39: ; preds = %25, %32, %30
%40 = phi i32 [ %31, %30 ], [ %33, %32 ], [ %27, %25 ]
%41 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %56, label %43
43: ; preds = %39
%44 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %56, label %46
46: ; preds = %43
%47 = call i32 @strtoul(i8* %15, i8** %4, i32 16)
%48 = load i8*, i8** %4
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 0
br i1 %50, label %56, label %51
51: ; preds = %46
%52 = trunc i64 %14 to i32
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %15, i32 %52)
%55 = call i32 @exit(i32 -1)
unreachable
56: ; preds = %43, %39, %46
%57 = phi i32 [ %47, %46 ], [ 183, %39 ], [ 184, %43 ]
%58 = trunc i64 %14 to i32
%59 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.6, i64 0, i64 0), i32 %58, i32 %57, i32 %17, i32 %40)
%60 = shl nuw nsw i64 %14, 4
%61 = add nuw nsw i64 %60, 430
%62 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 %61
%63 = trunc i32 %57 to i8
%64 = getelementptr inbounds i8, i8* %62, i64 4
store i8 %63, i8* %64
%65 = getelementptr inbounds i8, i8* %62, i64 8
%66 = bitcast i8* %65 to i32*
store i32 %17, i32* %66
%67 = getelementptr inbounds i8, i8* %62, i64 12
%68 = bitcast i8* %67 to i32*
store i32 %40, i32* %68
%69 = icmp ne i32 %57, 183
%70 = icmp ne i32 %16, 0
%71 = select i1 %69, i1 true, i1 %70
br i1 %71, label %73, label %72
72: ; preds = %56
store i8 -128, i8* %62
br label %73
73: ; preds = %72, %56
%74 = phi i32 [ %16, %56 ], [ 1, %72 ]
%75 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%76 = add i32 %40, %17
%77 = add nuw nsw i64 %14, 1
%78 = icmp ne i8* %75, null
%79 = icmp ult i64 %14, 4
%80 = select i1 %78, i1 %79, i1 false
br i1 %80, label %13, label %81
81: ; preds = %73, %2
%82 = load i32, i32* @O_CREAT
%83 = load i32, i32* @O_RDWR
%84 = or i32 %83, %82
%85 = call i32 @open(i8* %0, i32 %84, i32 438)
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %91
87: ; preds = %81
%88 = load i32, i32* @stderr
%89 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* %0)
%90 = call i32 @exit(i32 -1)
unreachable
91: ; preds = %81
%92 = call i32 @write(i32 %85, i8* %5, i32 512)
%93 = icmp eq i32 %92, 512
br i1 %93, label %98, label %94
94: ; preds = %91
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.8, i64 0, i64 0), i8* %0)
%97 = call i32 @exit(i32 -1)
unreachable
98: ; preds = %91
ret void
}